Answer to Question #253222 in Java | JSP | JSF for Tarurendra Kushwah

Question #253222

Write java program to read and write string using file.


1
Expert's answer
2021-10-24T05:53:46-0400


import java.io.*;
import java.util.*;


public class App {
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		System.out.print("Enter the source file name: ");
		String fileNameSource = keyBoard.nextLine();
		System.out.print("Enter the destination  file name: ");
		String fileNameDestination = keyBoard.nextLine();


		try {
			BufferedReader bufferedReaderSource = new BufferedReader(new FileReader(fileNameSource));
			FileWriter fileWriterDestination = new FileWriter(fileNameDestination);
			String line = bufferedReaderSource.readLine();
			while (line != null) {
				fileWriterDestination.write(line + "\n");
				line = bufferedReaderSource.readLine();
			}
			bufferedReaderSource.close();
			fileWriterDestination.close();
		} catch (IOException e) {
		}


		keyBoard.close();


	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS