Program to read a file and display it on the screen

/*Simple Java Program to read a file and display it on the screen */

/*First create an text file and save it as Output.txt*/

Code for NewFile.java
import java.io.*;
public class NewFile
{
public static void main(String args[])
{
try
{
FileReader fr=new FileReader("Output.txt");
BufferedReader br=new BufferedReader(fr);
String str=" ";

while((str=br.readLine())!=null)
{
System.out.println(str);
}
}
catch(FileNotFoundException fe)
{
fe.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}

}

Output :

Newest
Previous
Next Post »