Read an existing Text file and display the contents of Text file in a console output.

import java.util.*;
public class FileRead {
public static void main(String[] args) throws IOException{
Scanner input= new Scanner(;
System.out.print("Please enter the file name to Open : ");
String file_name = input.nextLine();
FileInputStream fstream = new FileInputStream(file_name);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br1 = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br1.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
//Close the input stream
System.out.println("File red successfully.");

Please enter the file name to Open : faizalps.txt
Hello World!!!!!!!!!!!!!!!
File red successfully.

Post a Comment

Copyright © Rough Record. Designed by OddThemes