Java object-oriented programming--17th I/O system

Source: Internet
Author: User

1. I/O operations refer to the operation of the input and output streams. Relative memory, when we read data from the data source into memory, is the input stream, also called the read stream. When we write data that is processed in memory to a data source, it is the output stream, also called the write stream.

2, stream by content classification: byte stream, character stream, object flow.

In fact, there is only one kind of stream: byte stream. The transmission of data is in binary mode at the bottom, so no matter what kind of stream, it is a byte stream. The character stream and object flow are encapsulated on a byte stream basis to facilitate manipulation of character data and object data.

3. The parent class of all byte streams: InputStream and OutputStream.

Parent class for all character streams: Reader and writer

4, the flow operation steps:

Establish a stream: establish a channel for transferring data between the memory and the data source;

Operation Flow: The data transmitted by the operation;

Close the stream: Closes the channel between the memory and the data source, freeing the resource.

5. When the file stream is manipulated, if the file does not exist, the read stream throws FileNotFoundException, and the write stream creates a new file, provided the directory where the file resides must exist. If the directory does not exist, it will also throw filenotfoundexception.

6. After the flow is used, it must be closed. If you do not close, waste memory resources, in addition, the write stream may not write data.

7. File class:

    • GetName (), get the file name;
    • GetParent (), get the file directory;
    • GetAbsolutePath () to obtain the absolute path of the file;
    • Exists (), determine whether the file exists;
    • Isfile () to determine whether the object is a file;
    • Isdirectory (), determine whether the object is a directory;
    • Listfiles (), get a list of all the files in a directory, including the files and directories, but not the contents of subdirectories;
    • Delete (), remove the file or directory (when you delete the directory), you must ensure that the directory is empty.
    • mkdir () to create a directory of the specified path

8. Recursion: Call the same method in one method.

9, object serialization: When the object is needed for data transmission, because of the large size of the object, so before the transfer of objects need to break up the object into a sequence of bytes, to facilitate transmission. This process, called object serialization. When you arrive at your destination, you need to restore the sequence of bytes to an object, which is called deserialization.

Java object-oriented programming--17th 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.