Blog Archive

Java Read File using BufferedReader example

package com.as400samplecode;

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

public class FileBufferedReader {

 public static void main(String[] args) {

  BufferedReader bufferedReader = null;

  try {

  String sCurrentLine;

  bufferedReader = new BufferedReader(new FileReader("data/newFile.txt"));

  while ((sCurrentLine = bufferedReader.readLine()) != null) {
   System.out.println(sCurrentLine);
  }

  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    if (bufferedReader != null){
     bufferedReader.close();
    }
   } catch (IOException ex) {
    ex.printStackTrace();
   }
  }

 }

}