Java Reference
In-Depth Information
standard input stream, System.in , is used after wrapping it in an In-
putStreamReader , which converts an input byte stream into an input char-
acter stream; if a filename is provided, an object of type FileReader is
created, which is a subclass of Reader .
The for loop counts the total number of characters in the file and the
number of spaces, using the Character class's isWhitespace method to
test whether a character is whitespace. At the end, the results are prin-
ted. Here is the output of the program when used on itself:
453 chars, 111 spaces
20.3.2. Writer
The abstract class Writer provides a stream analogous to OutputStream
but designed for use with characters instead of bytes. The methods of
Writer essentially mirror those of OutputStream , but add some other use-
ful forms of write :
public void write(int ch) throws IOException
Writes c h as a character. The character is passed as an int but
only the lowest 16 bits of the integer are written. This method
blocks until the character is written.
public abstract void write(char[] buf, int offset, int count) throws
IOException
Writes part of an array of characters, starting at buf[offset]
and writing count characters. This method blocks until the
characters have been written.
public void write(char[] buf) throws IOException
 
Search WWH ::




Custom Search