PrintWriter is essentially a character-oriented version of PrintStream. It provides the .formatted output methods print( ) and println( ). PrintWriter has four constructors.
Iava's PrintWriter objects support the print( ) and println( ) methods for all types including Object. It.an argument is not a simple type, the PrintWriter methods will call. the object's toString( ) method and then print opt the result.
Using Stream I/O
TIle following example demonstrates several of Java's 110 character stream classes and methods. This program Implements the standard we (word COW1t)command, The program has two modes: if no filenames are provided as arguments, the program operates on the standard input stream. If one or more filenames are specified, the program operates on each of them.
When executed with no arguments, WordCount creates an InputStreamReader object using System.in as the source for the stream. This stream is then passed to wet ), which does the actual counting. When executed with one or more arguments, WordCount assumes that these are file names and creates File Readers for each of them, passlength resultant FileReader objects to the we() method. In either case, it prints the results before exiting.