The BufferedWriter Stream

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

Answer:

A buffer is a section of memory used as a work area.

The BufferedWriter Stream

Disk input and output is more efficient when a buffer is used. For our small example programs it doesn't matter much. However, programs that do extensive IO should use buffers. The BufferedWriter stream is used for this with a character output stream.

BufferedWriter(Writer out)  
    Construct a buffered character-output stream 

The constructor is used as follows. Since FileWrite is a Writer it is the correct type for the parameter.

BufferedWriter out
   =  new BufferedWriter(new FileWriter("stuff.txt"));  

Different operating systems separate lines of text in different ways. To the annoyance of programmers everywhere, Microsoft operating systems use a two byte sequence at the end of a line of text, but Unix (and Linux) operating systems use just one byte.

QUESTION 13:

Is the '/n' character always appropriate at the end of a line?