Site Search:

Byte/Character cross IO

<Back

The stream classes are used for inputting and outputting only Character and String data.
Both have print(), println(), format(), printf(), which do not throw checked exceptions. Use checkError() to detect the presence of a problem after attempting to write data to the stream.

PrintStream extends OutputStream
Writes formatted character data to existing OutputStream. System.out is a PrintStream.
PrintWriter extends Writer
Writes formatted character data to existing Writer or OutputStream. new PrintWriter(System.out), true), new PrintStream(System.out) have same methods and do the same.


Truth is, only bytes. A character is just a sequence of bytes following certain encode/decode rule. Character stream classes are just convenient classes handling bytes streams easier.

InputStreamReader extends Reader
bridge byte to character, read bytes (decode) from an existing byte InputStream, as character Reader. FileReader extends InputStreamReader
OutputStreamWriter extends Writer
bridge character to byte, write character (encode) to an existing byte OutputStream as character Writer. FileWriter extends OutputStreamWriter.