Java                                                          Home : www.sharetechnote.com

 

 

 

 

Java - BufferedWriter

 

 

 

BufferedReader01.java

import java.io.*;

 

public class BufferedWriter01 {

 

    public static void main(String[] args)  {

        

        BufferedWriter bWriter = null;  

        FileWriter fWriter = null;  

        

          

        try {

            

            fWriter = new FileWriter("temp.txt");

    

            bWriter = new BufferedWriter(fWriter);

            bWriter.write("Hello World\r\n");

            bWriter.write("Hello\r\n");

            bWriter.write("World\r\n");

 

            

        } catch(Exception e) {

            e.printStackTrace();

        }

        

        try {

            bWriter.close();

        } catch(Exception e) {

            e.printStackTrace();

        }   

    

    }

 

}

 

      Output : The conents of temp.txt

       

        Hello World

        Hello

        World