Author: Jakob Jenkov Translator: Li Jing ([email protected])
Reader
Original link
Reader is the base class for all reader in Java IO. Reader is similar to InputStream, except that reader is based on character rather than byte-based. In other words, reader is used to read text, while InputStream is used to read raw bytes.
Keep in mind that Java internally uses UTF8 encoding to represent strings. One byte in the input stream may not be the same as a UTF8 character. If you read UTF8 encoded text in bytes from the input stream, and you try to convert the bytes read into characters, you may not get the expected results.
The Read () method returns a variable of type int that contains the contents of the read character (translator note: 0~65535). If the method returns-1, indicating that there are no remaining readable characters in reader, you can turn reader off. 1 is an int type, not a byte or char type, which is not the same.
You will typically use the subclass of reader instead of using reader directly. The subclass of reader includes Inputstreamreader,chararrayreader,filereader and so on. You can view the Java IO Overview to browse through the complete reader form.
Reader is typically associated with data sources such as files, character arrays, networks, and so on in the Java IO overview.
Writer
Original link
Writer is the base class for all writer in Java IO. Similar to the relationship between reader and InputStream, writer writes text based on characters rather than bytes, and OutputStream is used to write bytes.
Again, you'd better use writer's subclass, without having to use writer directly, because the subclasses are more explicit in their implementation and more expressive of your intentions. Common subclasses include Outputstreamwriter,chararraywriter,filewriter and so on.
Writer's write (int c) method writes the low 16 bits of the passed-in parameter to writer, ignoring the high 16-bit data.
original articles, reproduced please specify: reproduced from the Concurrent programming network –ifeve.com This article link address: Java Io:reader and writer
Java Io:reader and writer