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 and write the file itself.
DO NOT WRITE TO input.txt! That will cost a lot of points. Double check this. There is no sin worse than wiping out the client's input file due to carelessness.
Your class name should be FileCopy.
Your program must work in Eclipse, even if you use a different IDE to develop it. It is best to use Eclipse. I am starting you with a simple Eclipse project to get you ready for more complex projects.
Upload FileCopy.java.
A large part of your grade will be how well you follow these directions.
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; public class FileCopy { public static void main(String[] args) { File file = new File("input.txt"); try { Scanner fin = new Scanner(file); System.out.print("Enter output file name: "); PrintWriter pw = new PrintWriter("output.txt"); while (fin.hasNextLine()) { pw.println(fin.nextLine()); } System.out.println("file is copied successfully"); pw.close(); fin.close(); } catch (FileNotFoundException e) { System.out.println(file.getAbsolutePath() + " is not found!"); } } }
Get Answers For Free
Most questions answered within 1 hours.