Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

Java – The BufferedWriter class

The BufferedWriter is used to write text to a character output stream. It increases the performance.

Declaration

class BufferedWriter extends Writer

Constructors for BufferedWriter (CLICK HERE)

Methods defined in BufferedWriter (CLICK HERE)

Note

The BufferedWriter cannot create a connection with the file directly; therefore it needs to communicate with the help of Writer object.

Example

 import java.io.BufferedWriter;
 import java.io.FileWriter;
 import java.io.IOException;

 class BufferedWriterDemo 
 {
     public static void main(String args[]) throws IOException 
     {
         FileWriter f = new FileWriter("jkl.txt");
         BufferedWriter bw = new BufferedWriter(f);
         bw.write("Java");
         bw.newLine();
         bw.write("Its Beyond Simple");
         bw.flush();
         System.out.println("File Writing Successful");
         bw.close();
    }
 }

Output

File Writing Successful

The text file “jkl.txt” is created in the current working dictionary.

Java Programming Language BufferedWriter Class in File Handling

Leave a reply