For our common GBK Chinese and English is occupied by a byte, in Chinese, 2 for UTF-8, English is one, in Chinese, 3 for Unicode, English and Chinese are two operations on Java's stream byte stream and character stream for the two. 1, byte stream read operations are all inherited from a common super class java.io.InputStream class. All write operations are inherited from one ...
GBK in our common English, it is occupied by a byte, in Chinese 2
For UTF-8, English is one, in Chinese, 3
For Unicode, English and Chinese are two
Java's current operations are divided into two kinds of byte stream and character stream.
1, a byte stream
All read operations are inherited from a common super class java.io.InputStream class.
All write operations are inherited from a common super class java.io.OutputStream class.
InputStream and OutputStream are abstract classes.
InputStream has six low-level input stream:
Low flow
The use of flow
ByteArrayInputStream
Read data from memory array of bytes
FileInputStream
From the local file system to read data byte
PipedInputStream
Pipeline from the thread to read data byte
StringBufferInputStream
Read data byte from a string
SequenceInputStream
Low-level flow from two or more data bytes to read, when the reach the end of the stream flow from one to another stream
System.in
Read data byte from the user console
There is also a subclass of InputStream: filter flow java.io.FilterInputStream. Filter stream that can wrap up the basic flow, provide more convenient usage.
FilterInputStream class constructor for the FilterInputStream (InputStream), on the specified input stream, create an input stream filter.
Common FilterInputStream subclass as follows:
Filter input stream
The use of flow
BufferedInputStream
Buffer access to data to improve efficiency
DataInputStream
Read from the input stream of basic data types, such as int, float, double, or even one line of text
LineNumberInputStream
In the translation of line endings, based on maintaining a counter that shows which line is being read.
PushbackInputStream
Pushed back to allow the data bytes to the stream of first
OutputStream (abbreviated)
The structure of OutputStream and InputStream is the same.
2, the character stream
Note: It is introduced in jdk1.1 inside, above the byte stream is introduced in jdk1.0. When used to process text data, select the character stream better than the byte stream. But the basic data types only way developers can continue to use the byte stream.
All read operations are inherited from a common super class java.io.Reader class.
All write operations are inherited from a common super class java.io.Writer class.
Reader and Writer is the same abstract class.
Reader's common subclass as follows:
Low-level reader
The use of flow
CharArrayReader
Read data from a character array
InputStreamReader
FileReader (InputStreamReader sub-category)
From the local file system, a sequence of characters to read
StringReader
Read a sequence of characters from the string
PipedReader
Pipeline from the thread to read a sequence of characters
InputStreamReader highlight:
InputStreamReader to read from the input data stream, the connection input stream on the reader. Such as:
new InputStreamReader (System.in)
Constructor:
InputStreamReader (InputStream)
Use the default character encoding, create a InputStreamReader.
InputStreamReader (InputStream, String)
With a named character encoding, create a InputStreamReader.
Commonly used filters reader:
Filter reader
The use of flow
BufferedReader
Buffered data access, to improve efficiency
LineNumberReader (BufferedReader sub-category)
Maintains a counter that shows which line is being read.
FilterReader (abstract class)
Create a filter to provide a class can extend this class
PushbackReader (FilterReader sub-category)
Pushed back to allow the text data stream reader
These filters reader can pass a Reader as a constructor parameter.
Writer (abbreviated)
The structure of Writer and Reader are the same.
Byte stream is the most basic, the characters flow in order to deal with characters of their argument.
new BufferedReader (new InputStreamReader (client.getInputStream ())); explained:
client.getInputStream () is a byte stream;
InputStreamReader stream the byte stream into characters;
BufferedReader buffered character stream, makes it possible to use the readline () and other methods to read a line directly.
No comments:
Post a Comment