Friday, October 16, 2009

Code snippet to read and display a file from a folder (Java)

package files;

import java.io.BufferedReader;
import java.io.IOException;

public class FileReader 
{
 public static void main(String[] args) throws IOException 
 {
  BufferedReader fr = new BufferedReader(new java.io.FileReader
  ("D:\\Amit\\JavaAssignments\\Lab3\\MyBook.java"));//Give the complete path of the file you want to read. Above is an example.

  String str;
  while((str = fr.readLine())!= null)
  {
   System.out.println(str);
  }
 }

}

No comments:

Post a Comment