JAVA I/O system

Source: Internet
Author: User

The definition of Java I/O system: Unify the classes placed in the Java.io package and the Java.nio package.

1, the concept of flow <stream>: When the program needs to read the data, it will open a stream to the source device, the data source device can be file, memory and network connection.

2, the basic characteristics of the flow: liquid and direction.

3. Classification of streams:

A is divided by the direction of the data flow: the input stream, which reads data from the data source into the program, the input stream in the IO packet inherits from InputStream or reader. );

The output stream (writes data from the program to the data destination, and the output stream in the IO packet is inherited from OutputStream or writer. )

             b By different points of the smallest unit of processing data: The byte stream (the smallest unit is the byte stream in the Byte,io package inherits from the abstract class InputStream or OutputStream. );

                                                                      The character stream (the smallest unit is the byte stream in the Char,io package is inherited from the abstract class reader or writer.) )

Note: It is more efficient and convenient to read and write text-based data with character streams.

c According to the function of the stream: node stream < low-level flow > (stream that can read or write data directly to a particular data source);

Process Flow < Advanced streaming > (not directly connected to the device, but connected to an existing stream < node stream or process flow > above)

Note: The specific classes in all I/O classes are inherited from four abstract classes: Inputstream,outputstream,reader,writer.

ii. steps for all I/O operations:

1, create a stream

2. Operation Flow

3. Close the Stream

The file class can manipulate the file, but it is not a stream and it cannot manipulate the contents of the file.

Iv. byte stream: Used to process binary files.

1. Advanced byte stream:

A, according to the function of:

Filter Stream Class (buffer stream, data stream, count, push back input stream, print output stream);

Object flow (serialization, deserialization);

Note: In order to implement object serialization, the corresponding class must implement the Java.io.serializable interface; The property modified by transient cannot be serialized.

merger;

Character Stream;

The following methods can be used to solve the problem that the property modified by transient cannot be serialized:

The first step:

public void ReadObject (Java.io.ObjectInputStream in) throws ioexception,classnotfoundexception{

Content

                       }

Step Two:

public void WriteObject (Java.io.ObjectOutputStream out) throws ioexception{

Content

}

JAVA I/O system

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.