JAVA Base IO Operations

Source: Internet
Author: User
Tags object serialization

Java.io operation is the basis of the Java Foundation, if no IO operation program will not run, so, and review the contents of the java.io operation, the object serialization is the basis of the Java EE, is the implementation of distributed deployment and call the foundation, there are a lot of file system, Read and write network resources, and so on.

For the inside of the personal feel of the more important knowledge to do a figure summed up a bit. As follows:



Here is a summary of the key points of understanding and use

1. Conceptual understanding

The concept of java.io has always been understood a little deviation, first of which involves a concept of directionality, that is, where our data from where to go, in the java.io operation and many concepts and classes in the implementation of the definition, the author is from the memory point of view, such as you need to save some data to the computer's hard disk, then you say Is it input or output? In fact, this is the output operation, the reason you will feel is the input operation because you stand in your own perspective, thinking that the data is written to disk, you can actually write data through memory to disk, for memory this is the output operation

Only when the operation class is correctly selected to manipulate the data, the input and output operations are correctly understood first.


2. Stream operations

Write another file from one file, as follows

<pre name= "code" class= "java" >public static void Main (string[] args) {          try           {   //create byte input stream        FileInputStream fis=new FileInputStream ("f:\\ song \\Dreamcatcher.txt");        Create byte output stream        FileOutputStream fos=new fileoutputstream ("F:\\new.txt");                Byte[] Buf=new byte[64];        int hasread=0;        The loop fetches data from the input stream while        ((Hasread=fis.read (BUF)) >0) {//Read each time, how many        fos.write (Buf,0,hasread) are written to the output stream of the file;        System.out.println (New String (Buf,0,hasread));}        System.out.println (New String (BUF));                } catch (Exception e) {              e.printstacktrace ();          }       }  




3. Serialization of objects

All classes of objects that may be transmitted over the network should be serializable, or the program will have exceptions such as RMI remote method calls, which are the basis of Java EE, parameters and return values in the process, and all object classes that need to be saved to disk must be serializable . the serialization of the underlying implementation is achieved through the Io stream class.

The version number of the serialized object is used

There are two of functions

First, one is to deserialize multiple objects to avoid the occurrence of an object being serialized a lot

For example:

For example, the client has two teacher objects, referring to the same student object, and receives three student objects when the server side deserializes through IO.

An object of reference type needs to be serialized when serializing, so that the student object is serialized every time the teacher object is deteriorated, and if there is a version identity system that instantiates the second teacher object, it detects that there are no student objects, if any, will no longer serialize.

Second, convenient service-side upgrade, if there is no version number each time you compile the class, the system will automatically assign a version number, after modifying the class structure two times before and after the inconsistency, version number to avoid.


Summary

There are only a few abstract classes available for the top layer of the IO operation, and the underlying implementation has more than 10 classes that encapsulate the underlying layer by decorating the pattern, masking the details of the underlying data processing; The object serialization mechanism based on IO operations is now the basis for our development of the Java Architecture for distributed applications, which is the underlying , for the above structure stability is very important, the economic base determines the superstructure.

JAVA Base IO Operations

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.