today just read the Java IO Stream operation, the main context looked over, can not guarantee the use of later can be handy, but at least when used to know that there is such a function can be achieved, the following for a brief summary of learning:
IO stream is mainly used for data manipulation on hard disk, memory, keyboard and other processing devices, according to the data type of processing data can be divided into: byte stream (abstract base class is InputStream and OutputStream) and character stream (abstract base class for reader and writer). Depending on the flow direction, it can be divided into: input stream and output stream. The main structure can be used to indicate:
The main differences between character streams and byte streams are:
1. When the byte stream is read, a byte is returned, and the character stream is read to one or more bytes using the byte throttle (the number of bytes in Chinese corresponds to two, which is 3 bytes in the UTF-8 Code table). First, look for the specified encoding table and return the found characters.
2. The byte stream can handle all types of data, such as: Pictures, Mp3,avi video files, and character streams can only handle characters data. As long as you are dealing with plain text data, you should prioritize the use of character streams, in addition to byte streams.
Io stream can be divided into two categories, node flow and processing flow.
One: node stream type
This type can read and write data from or to a specific location or node. The main types are as follows:
Two: Processing flow type
The type is a link to an existing stream and encapsulation, through the function call of the encapsulated stream to implement the data read and write, processing the flow of the construction method always take a other stream object as a parameter, a stream object through the other flow of multiple wrappers, called the link of the stream. The main can be divided into several:
1. Buffer stream: Bufferedinputstream/bufferedoutputstream and Bufferedwriter/bufferedreader. They can provide the operational efficiency of the convection.
Write Buffer object: BufferedWriter bufw=new bufferedwriter (New FileWriter ("Buf.txt"));
Read Buffer object: BufferedReader bufr=new BufferedReader (New FileReader ("Buf.txt"));
Actual example Write buffer:
The stream of that type has a readline () method when it reads the buffer. such as: BufferedReader bufr=new BufferedReader (New FileReader ("Buf.txt")), this time you can use: Bufr.readline (), read one line, and when the row is marked, The character data before the row tag is returned as a string, and null is returned when the end is read. The principle is also the Read method of the stream object associated with the buffer, except that each time it is read to a character, it is not done in the first place, it is temporarily stored, and the data stored in the temporary container is returned at once when the carriage return tag is read.
The stream of that type has a newline () method when it writes to the buffer. such as: BufferedWriter bufw=new bufferedwriter (New FileWriter ("Buf.txt")), this time you can use: Bufw.newline (); When the loop is written, it is written in a newline.
2. Conversion stream: Inputstreamreader/outputstreamwriter. This type is a bridge between the byte stream and the character stream that can be encoded in the specified encoding of the bytes of data read.
The main constructors are:
Input stream
InputStreamReader (); Through the constructor initialization, using the system is the default encoding table GBK.
InputStreamReader (inputstream,string charSet); //Through the constructor initialization, the byte stream is converted into character streams and the encoding table is specified.
Output stream
OutputStreamWriter (); Through this constructor initialization, using the System default encoding table GBK.
OutputStreamWriter (outputstream,string charSet); By initializing the constructor, the byte stream is converted into a character flow and the encoding table is specified.
Summary of IO Learning in Java