Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Project Java

christypm11
christypm11 


Write a program that will make a copy of a text file, line by line. Read the name of the existing file and the name of the new file – the copy – from the keyboard. Use the methods of the class File to test whether the original file exists and can be read. If not, display an error message and abort the program. Similarly, see whether the name of the new file exists. If so, display a warning message and allow the user to either abort the program, overwrite the existing file, or enter a new name for the file. Create the existing file with a text editor (e.g. you may use Word but save the file as a text (.txt) file). Sample program executions follow: Enter the name of the existing file: old.txt Enter the name of the new file: new.txt Copying old.txt into new.txt Enter the name of the existing file: old.txt Enter the name of the new file: new.txt old.txt does not exist. Exiting program. Enter the name of the existing file: old.txt Enter the name of the new file: new.txt new.txt already exists Choose from the following choices: 1 – Exit the program 2 – Overwrite the existing file 3 – Enter a new name for the file Enter a number: 1 Exiting program Enter the name of the existing file: old.txt Enter the name of the new file: new.txt new.txt already exists Choose from the following choices: 1 – Exit the program 2 – Overwrite the existing file 3 – Enter a new name for the file Enter a number: 2 Overwriting new.txt Enter the name of the existing file: old.txt Enter the name of the new file: new.txt new.txt already exists Choose from the following choices: 1 – Exit the program 2 – Overwrite the existing file 3 – Enter a new name for the file Enter a number: 3 Enter a new name for the file: newer.txt Copying old.txt into newer.txt Attachments
Tags Clarifications

Answers

Java - File Rename - Solution

dickersonka
dickersonka 



Attached is the solution to the Java - File Rename assignment Attachments
FileRename.java (2 K) Download Preview
public static void copyFile(File sourceFile, File destFile){ try { FileReader fileReader = new FileReader(sourceFile); BufferedReader bufferedReader = new BufferedReader(fileReader); FileWriter fileWriter = new FileWriter(destFile); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); String line = ""; while((line = bufferedReader.readLine()) != null){ bufferedWriter.write(line);

Screenshots
Purchase Answer

FileCopy in Java

SW_wizard
SW_wizard 



Code implemented as per the requirements. Attachments
CopyFileProject.zip (1 K) Download
Preview
break; default : System.out.println("Not a valid selection... Exiting"); System.exit(0); } } else { System.out.println("writing "+ sourcefile + " to "+ destfile); writeFile(sourcefile, destfile); } } public static void writeFile(String source, String dest){ Writer output = null;

Preview
Contents will be copied to new

Screenshots
Purchase Answer