Java--io

Source: Internet
Author: User

In Java programming, we take IO-stream operations when we get and output information.
We typically manipulate this information through a file, so the first thing to do is to manipulate the file. The Java.io.File class represents the file (directory) information (name, size, etc.), and can access the contents of the file, we can use the file class in the program to manipulate files and directories on the hard disk. Generally we commonly used include get current path Getcanonicalpath (); Create a new file directory mkdir (); Determine if the file exists exists (); Create a new File Object CreateNewFile () ; Get all files under the path Listfiles (); Filter FileFilter class for the action file; Determine the file name suffix EndsWith () for a string type.
The IO stream in Java is the basis for implementing input/output. The direction of the flow is different: it is divided into input stream and output stream. Varies by processing data units: divides into byte stream (8 bit byte) and character stream (16 bit char). According to different functions: divided into node stream and processing flow. All byte-oriented stream classes inherit from the InputStream (input stream) or outputstream (output stream), which are abstract classes, and the character-oriented stream classes inherit from the two abstract classes reader (read stream of characters) or writer (write character stream). We can use their subclasses to accomplish different functions. All of the flow class operations are divided into the establishment flow, the operation flow, the close flow. The commonly used file input and output streams are FileInputStream and FileOutputStream.
The fewer times the program accesses the IO, the higher performance is due to the speed of the CPU and memory, which is much faster than a hard disk or other external device. In order to improve the performance of IO (input and output), we add buffered streams Bufferedinputstream && Bufferedoutputstream to write and read operations, which provides a buffer for IO operations. This reduces the number of times the IO is accessed.
In Java, everything is an object, and in a distributed environment it is often necessary to pass an object from one end of the network or device to the other, which requires a protocol that can transmit data at both ends, and the Java serialization mechanism is created to solve the problem. In short, it is the state of the various objects stored in memory, and the state of the saved objects is read again. Under what circumstances do we need to serialize? 1. When you want to save objects in memory to a file or database, 2, when you want to use sockets on the network to transfer objects, 3, when you want to transfer objects through RMI. Serialization is the process of converting an object into a byte sequence, describing the objects as a series of bytes, and deserialization is the process of re-building these bytes into an object. Serialization consists of two important concepts 1, the serialized stream (ObjectOutputStream), which translates an object into a serialized stream. 2. Serialization interface (Serializable). The object must implement a "serialization interface" to serialize, otherwise the serialized exception will appear, Serializable is an empty interface, there is no method, only as an identity of the serialization.

Java--io

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.