Tuesday, May 4, 2010

Source code to read content of File

Here you will find the source code to read the content of file.

  1. Create the FileReader object using file name as an input to FileReader constructor.
  2. Pass that FileReader object to BufferedReader.
  3. Read the line from BufferedReader object till readline gets null.
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class FileReadTest {

    public static void main(String[] args) {
         try {
            BufferedReader br = new BufferedReader(new FileReader("C:\\temp\\test.txt"));
            String line = "";
            while((line = br.readLine()) != null)
        } catch (FileNotFoundException e) {
        } catch (IOException e) {

No comments:

Post a Comment