Organizing Notes--java Basics (data flow operations)

Source: Internet
Author: User
Tags file copy serialization

IO stream:

Is the data of the operation plain text?

Yes: Reader,writer

Not: Inputstream,outputstream

Why is the byte stream received with an int instead of the bytes?

-1 represents the return condition (i.e., 11111111 of the complement form) that is most likely to be read by a byte stream.

It is assumed to be a detection door, with an int is the data before adding 24 0, disguised through the detection door, in the output will default to remove 24 0.

Why not use the word stream to manipulate characters, but also the character stream?

Because the number of bytes in a different encoding table is not the same for Chinese.

Precautions:

1. Byte stream write character to use GetBytes ();

The 2.Writer comes with a 2k buffer, which writes the contents into the buffer if the stream is not closed.

Buffered stream (with decorative design mode):

Unique method:

1.readLine () reads a line and returns without a newline character.

2.newLine () writes a newline character.

Add: The difference between newline and \ r \ n is that newline is cross-platform, and \ r \ n is only applicable on window.

Java.util.Properties: An object (subclass of Hashtable) that can persist key values for storage

IO stream core Code, copy

 Public Static voidMain (string[] args)throwsIOException {fileinputstream fis=NewFileInputStream ("E:\\read.txt"); FileOutputStream Fos=NewFileOutputStream ("E:\\write.txt");//int len;//byte[]arr=new byte[1024];intb;//While ((Len=fis.read (arr))!=-1) {//Fos.write (Arr,0,len); while((B=fis.read ())!=-1) {fos.write (b);} Fis.close (); Fos.close (); System.out.println ("File Copy Code");}

File Class (abbreviated):

Serialization:

is to convert the in-memory Java object into a platform-independent binary stream, allowing it to be persisted on disk.

Serializable externalizable The difference between two serializable interfaces:

1. The former performance is poor, but simple so commonly used.

2. The latter has good performance, but increases the complexity of programming.

The transient keyword, when modified, does not perform the JVM's default serialization operation. After being deserialized, the value of the transient variable is set to the initial value, such as the int type is 0, and the object type is null.

The deserialized Java object must provide a class file for the object, and how can Java guarantee two class file compatibility as the project is upgraded?

The Java serialization mechanism allows the serialization class to be provided with a private static final Serialversionuid value that identifies the serialized version of the Java class.

WriteObject and ReadObject methods:

1. In the serialization process, if the writeobject and ReadObject methods are defined in the serialized class, the virtual opportunity attempts to invoke the WriteObject and ReadObject methods in the object class for user-defined serialization and deserialization.

2. If there is no such method, the default call is the Defaultwriteobject method of ObjectOutputStream and the Defaultreadobject method of ObjectInputStream.

3. The user-defined WriteObject and ReadObject methods allow the user to control the serialization process, such as the ability to dynamically change the serialized value during serialization.

Precautions:

1. Reflection, serialization, and deserialization all break the single-case design pattern.

2. The resulting object is a new object by serializing and deserializing the Singleton, which destroys the singleton of the Singleton.

3. To define the Readresolve method in Singleton, and specify the generation strategy of the object to be returned in the method, you can prevent the singleton from being corrupted.

Organizing Notes--java Basics (data flow 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.