IN JAVA.
Write a program that reads a file (provided as attachment to this assignment) and writes the file to a different file with line numbers inserted at the beginning of each line.
For example if file input is:
This is a test
File output should be
1. This is a test
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BELOW FROM NOTEPAD FILE.
This file contains
lines of text to
determine if you can
properly read and
write from a file.
Program
import java.util.*;
import java.io.*;
//class
class ReadWriteFile
{
//main method
public static void main(String[] args) throws
IOException
{
File file = new
File("input.txt");
Scanner in = new
Scanner(file);
FileWriter fw = new
FileWriter("output.txt");
PrintWriter out = new PrintWriter(fw);
int i = 1;
while(in.hasNext())
{
//read a line
from file
String line =
in.nextLine();
//write to
console
System.out.println(line);
//write to
file
out.printf("%d.
%s\n", i, line);
i++;
}
//close FileWriter
fw.close();
}
}
input.txt
This file contains
lines of text to
determine if you can
properly read and
write from a file.
output.txt
1. This file contains
2. lines of text to
3. determine if you can
4. properly read and
5. write from a file.
IN JAVA. Write a program that reads a file (provided as attachment to this assignment) and...
Please do in java as simply as possible with code available for copy and comments Write a program that reads a file (provided as attachment to this assignment) and writes the file to a different file with line numbers inserted at the beginning of each line. Throw an exception if the file does not exist. An error message should result. For example if file input is: This is a test File output should be 1. This is a test I...
Lab Assignment 4B Modify your program in Lab Assignment 4A to throw an exception if the file does not exist. An error message should result. Use the same file name in your program as 4A, however, use the new input file in 4B assignment dropbox. Lab 4A: Write a program that reads a file (provided as attachment to this assignment) and writes the file to a different file with line numbers inserted at the beginning of each line. Test with...
Write a program in Java that reads the file and does two things: Write to an output file called dataSwitch.txt the same data from the input file, but switch the order of the data entries on each line. For example, if the first line of the input file is “90001 57110”, the first line of the output file would be “57110 90001”. Additionally, print to the screen the number of lines in the file with a label
( IN JAVA): Write a program that reads each line in a file, and writes them out in reverse order into another file. This program should ask the user for the name of an input file, and the name of the output file. If the input file contains: Mary had a little lamb Its fleece was white as snow And everywhere that Mary went The lamb was sure to go Then the output file should end up containing: The lamb...
This assignment involves 2 Java programs 1) Write a Java program to read a CSV (Comma separated values) text file. The text file will contain comma separated values in each line. Each line contains data in this format: String(20), String(5),String(10), double. There will be multiple lines with each line containing the same number of values. Ask the user to enter the path for the CSV file for reading the file. After reading the data from the file output the data...
Write a program that reads a file named input.txt and writes a file that contains the same contents, but is named output.txt. The input file will contain more than one line when I test this. Do not use a path name when opening these files. This means the files should be located in the top level folder of the project. Do not use a copy method that is supplied by Java. Your program must read the file line by line...
Using Java how would I write a program that reads and writes from binary or text files and gives me an output similar to this? Example Output: --------------------Configuration: <Default>-------------------- Enter the file name: kenb Choose binary or text file(b/t): b Choose read or write(r/w): w Enter a line of information to write to the file: lasdklj Would you like to enter another line? Y/N only n Continue? (y/n)y Enter the file name: kenb Choose binary or text file(b/t): b Choose...
java question: Write a program that reads in data from a text file named in.txt. Compute the sum of all the valid integers in the input file. Likewise, compute the sum of all the valid doubles in the input file. Write the former to an output file called int_total.txt, and write the latter to an output file called double_total.txt. B) Write a program that converts the Java source code from the next-line brace style to the end-of-line brace style. For...
Java Exceptions Suppose a library is processing an input file containing the titles of books in order to remove duplicates. Write a program that reads all of the titles from an input file called bookTitles.inp and writes them to an output file called uniqueTitles.out. When complete, the output file should contain all unique titles found in the input file. Create the input file using Notepad or another text editor, with one title per line. Make sure you have a number...
In Python, write a program that reads a text file that is provided by the user - ensure that the file exists before processing it! The file might be in a different directory, so be sure to test you logic - the user will provide the absolute path to the file if it is not in the same directory as the Python script! You should then ask the user for what string to search for in the file. Your program...