Java IO Learning Notes: Concepts and principles

Source: Internet
Author: User

Java IO Learning Notes: Concepts and principles

first, the conceptThe operation of the file in Java is done in a streaming fashion. A stream is an ordered set of data sequences in Java memory. Java reads the data from the source (file, memory, keyboard, network) into memory, forms a stream, and then writes those streams to another destination (file, memory, console, network), which is called a stream because the data sequence operates at different points in different parts of the source. Second, classificationStream classification, Java Stream classification is rich, just contact people will feel dizzy after seeing. There are many ways to classify streams: 1, according to the direction of input, input stream and output stream, the reference object of input and output is Java program. 2, according to the processing data units different points, byte stream and character stream, the byte stream read the smallest unit is a bytes (1byte=8bit), and the character stream can read one character at a time (1char = 2byte = 16bit). 3, according to the different points of the function, sub-node flow and processing flow, the node flow is directly from a source read and write data stream (this stream has not been wrapped and modified), processing flow is on the basis of the node flow encapsulation of a stream, FileInputStream is a contact flow, you can read data directly from the file, But the Bufferedinputstream can be packaged with FileInputStream, making it a buffer function. In fact, in addition to the above three categories, there are some commonly heard some categories such as: Object flow, buffer stream, compressed stream, file flow and so on. is actually a sub-classification of node flows and processing streams. Of course you can also create new stream types as long as you need. three, the relationship of flow classificationRegardless of how rich and complex the classification of the stream is, its roots come from four basic classes. The relationship between the four classes is as follows:
BYTE stream Character Stream
Input stream InputStream Reader
Output stream OutputStream Writer
iv. Conversion of byte-stream and character stream1, from byte stream to character streams: InputStreamReader, OutputStreamWriter class can be implemented. 2, from character flow to byte stream: You can get char[] array from the character stream, convert to string, then call the API function of String GetBytes () get to byte[], and then you can pass Bytearrayinputstream,  Bytearrayoutputstream to convert to a byte stream. The above knowledge is the foundation of Learning Java Stream, the operation of convection is very easy, Java API provides a rich stream processing class, the API is not bad, look at the document to get started.

Java IO Learning Notes: Concepts and principles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.