Java                                                          Home : www.sharetechnote.com

 

 

 

 

Java - BufferedReader

 

 

 

BufferedReader01.java

import java.io.*;

 

public class BufferedReader01 {

 

    public static void main(String[] args)  {

        

        BufferedReader bReader = null;  

        FileReader fReader = null;  

        

          

        try {

            fReader = new FileReader("temp.txt");       

            bReader = new BufferedReader(fReader);

            String data = bReader.readLine();

 

            while(data != null) {

                System.out.println(data);

                data = bReader.readLine();

            };

            

        } catch(Exception e) {

            e.printStackTrace();

        }

        

        try {

            bReader.close();

        } catch(Exception e) {

            e.printStackTrace();

        }   

    

    }

 

}

 

contents of temp.txt

Hello World

Hello

World

 

      Output :

       

        Hello World

        Hello

        World