Monday 14 November 2016

Working with BufferedWriter



 BufferedWriteris a Writer that buffers output.
 Using aBufferedWriter can improves performance by reducing the number of times data is actually physically written to the output stream.
 It hastwo constructors:
BufferedWriter(Writer outputStream)
BufferedWriter(WriteroutputStream, intbufSize)
The first form creates a buffered stream using a default buffer size. In the second, the size of the buffer is passed in bufSize.
 Example:
import java.io.*;
classBufferedwriter
{
public static void main(String args[]) throws IOException
 {
  String s="Hello this information is written to file using filewriter\nIt is used for writting";
FileWriter f=new FileWriter("File1.txt");
char b[]=new char[s.length()];
s.getChars(0,s.length(),b,0);
BufferedWriterbw=new BufferedWriter(f);
bw.write(b);
f.close();
System.out.println("Data Successfully Written");
 }
}
Output:
Data Successfully Written

No comments:
Write comments