PrintWriter

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:

No.

PrintWriter

The class PrintWriter is used to deal with the end-of-line problem and other frustrations of file output. PrintWriter provides many methods that are useful for "printing" characters. ("Printing" in this context means sending characters to an output destination, not usually a hard-copy printer.) The println() method uses the approprate line separator for the operating system the program is running on. Often a PrintWriter stream is connected to a BufferedWriter stream which is connected to a FileWriter.

printWriter Pipe

For small programs, where buffering is not needed, the middle pipe (the BufferedWriter) can be omitted.

A further advantage of PrintWriter is that none of its methods (including println()) throw exceptions. Usually output is more reliable than input (because the program has control over its output), so exception handling is sometimes not needed.

QUESTION 14:

Can a PrintWriter be used alone?