Java Note 19. In-depth parsing of the hierarchy of I/O programming streams

Source: Internet
Author: User

deep parsing of the hierarchy of I/O programming streams Reprint please indicate source:http://blog.csdn.net/u012637501( embedded _ small J Sky ) most applications require data exchange with external devices, and the most common external devices include disks and networks. The so-called I/O (input/output abbreviation), refers to the application of these devices data input and output . In the program, the keyboard is treated as an input file, and the display is used as an output file. The Java language defines a number of inputs and outputs that are specifically responsible for various methods, which are java.io in the package. first, understanding the concept of flow 1. Data Flow A data stream is a set of continuous sets of data that a data writer can write to a data flow pipeline over a period of time, which forms a long stream of data sequentially. The I/O Stream class can be divided into node stream class and processing flow class (or wrapper Class), which are described as follows: (1) Node Stream class : The class that the program uses to directly manipulate the target device is called the node stream class. (2) Packaging class: The program can call the node stream class through an indirect flow class , in order to achieve more flexibility and easy to read and write various types of data , the indirect flow class is the wrapper class (Processing flow Class). 2. Byte stream and character streamall of the files are stored in byte (byte) storage, and the characters that are not files on the disk are encoded into bytes, and then the bytes are stored to disk. When reading a file (especially a text file), it is also a byte-by-byte read to form a sequence of bytes. The main difference between a byte stream and a character stream is their way of handling. (1) stream of bytes (byte stream)byte stream is the most basic, using ASCII encoding, all InputStream and OutputStream subclasses are, mainly used in processing binary data. The byte Stream processing Unit is 1 bytes, It is a byte or byte array in bytes, which is better for processing audio files, pictures, songs, and so on. (2) character stream (char stream)A character stream is processed by a cell that is a 2-byte Unicode character, manipulating characters, character arrays, or strings, respectively. A character stream is made up of characters that the Java Virtual machine converts bytes into 2-byte Unicode characters, primarily for processing multiple languages or text. Learn a trick: The difference between a byte stream and a character stream ? Difference 1: The character Stream processing unit is a 2-byte Unicode character, respectively, manipulating characters, character arrays, or strings, while the byte stream processing unit is 1 bytes, manipulating bytes and byte arrays. Difference 2: The byte stream itself does not use the buffer (memory) in the operation, the file itself is directly manipulated, and the character stream is used in the operation of the buffer, through the buffer to manipulate the file.

Difference 3: The byte stream can be used for any type of object, including binary objects, whereas character streams only handle characters or strings;Difference 4: The byte stream provides the ability to handle any type of IO operation, but it cannot handle Unicode characters directly, and a character stream is available.
class-level relationships in IO packagesThe object in Java that can read data from it is called an input stream, and the object to which it is written is called the output stream. 1. Byte stream (1) byte input stream class
>inputstream class: Is the parent class of all bytes input stream, is an abstract class;>stringbufferinputstream class: is a basic media stream used to read data from a stringbuffer (character array);>bytearrayinputstream class: is a basic media stream used for the degree of data from a byte byte array;>fileinputstream class: The most basic file input stream for reading data from a file;>pipeinputstream class: This class introduces the concept of pipelines in a stream, which is used to read data from pipelines shared by other threads; >sequenceinputstream class: converts 2 or more InputStream objects into a inputstream. Note: ObjectInputStream, all filterinputstream subclasses are decorative streams. >datainputstream class: used in general and DataOutputStream pairing, provides a large number of methods to read basic data types. >bufferedinputstream class: The use of this object prevents the IO from being frequently manipulated every time a byte is read. Reads a byte buffer from the buffer. >linenumberinputstream class: tracks the line number in the input stream. You can call the Getlinenumber () and Setlinenumber (int) methods to get and set the line number. >pushbackinputstream class: You can put it back into the cache after the last byte is read. (2) byte output stream class
>outputstream class: Is the parent class of all output byte stream, it is an abstract class;>bytearrayoutputstream class: is a basic media stream used to write data to a byte array;>fileoutputstream class: is a basic media stream used to write data to local files;>pipedoutputstream class: To write data to a pipeline shared with other threads, any information written to this object is placed in the cache of the corresponding PipedInputStream object, which completes the thread communication and realizes the concept of "pipeline";Note: ObjectOutputStream and all filteroutputstream subclasses are decorative output streams>dataoutputstream class: Commonly used in conjunction with DataInputStream, provides a large number of methods of writing basic data types;>printstream class: Used to produce formatted output information (generally in Java programs dataoutputstream for data storage, which is the function of the persistence layer in the EE, printstream to complete the function of the display, Similar to the function of the presentation layer in the Java EE);>bufferedoutputstream class: Use this class to avoid frequently writing data to Io, that is, to write data to a buffer, and then call the Flush method to write data once and empty the cache. 2. Character Stream (1) character input stream class
>reader class: Is the parent class of all the input character streams, for an abstract class;>chararrayreader class: Is a basic media class for reading data from a char array;>stringreader class: Is a basic media class for reading data from a string;>pipereader class: writes character data to a pipeline that is used to share with other threads; >inputstreamreader class: Is a connection byte stream and character stream of the bridge, it will be a stream of bytes into a character streams, its sub-class FileReader is actually a specific class to implement this function.>bufferedreader class: Is an adorner, and its subclasses are responsible for decorating other reader objects;>filterreader class: Is the parent of all custom-specific decorative streams whose subclasses pushbackreader the reader object, adding a line number; (2) Character output stream class
>writer class: Is the parent class of all output character streams, it is an abstract class;>chararraywriter class: is a basic media stream used to write data to a char array in character form;>stringwriter class: is a basic media stream used to write data to a string (string) as a character;>pipedwriter class: Writes data to a pipeline that is used to share with other threads;>bufferedwriter class: is an adorner for writer to provide buffering function;>outputstreamwriter class: Is the bridge that OutputStream to writer transforms, its subclass FileWriter is actually a concrete class that realizes this kind of function.

Java Note 19. In-depth parsing of the hierarchy of I/O programming streams

Related Article

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.