Posts

Showing posts with the label flush method

Java Buffered Writer Issue

Using Buffered Writers is an efficient way to write the output to a file where hard disk accesses are costly. The main idea behind the Buffered Objects is(Here it is the buffered writer) having a buffer which is, writing the output to a memory location in the computer's main memory(which is faster than writing to hard disk). And then once the Buffer is filled with enough data, the whole buffer is written to the hard disk. However, this can bring up some issues which are difficult to find. One of such issues is my attempt to write to a text file using a buffered writer. I used the following code. FileWriter writer; BufferedWriter bWriter ; PrintWriter pwriter ; writer = new FileWriter (new File("./output. txt "); bWriter = new BufferedWriter (writer); pwriter =new PrintWriter ( bWriter ); int i=0; while(i pwriter . println (i); i++; ...