Sort notes -- Java BASICS (data flow operations) -- java Data Flow
IO stream:
Is the operated data plain text data?
Yes: Reader, Writer
No: InputStream, OutputStream
Why does Byte stream receive data with int instead of Byte?
-1 indicates the return condition (that is, 11111111 of the complement form). It is very likely to be read by throttling.
Suppose it is a detection door. If int is used, 24 zeros are added before the data. The detection door is disguised and 24 zeros are removed by default during output.
Why not use byte stream operation characters, but also byte stream?
Because the numbers of Chinese Characters in different encoding tables are different.
Note:
1. To write characters to byte streams, use getBytes ();
2. Writer comes with a 2 K buffer. If the stream is off, the content will be written to the buffer.
Buffer stream (decorative design mode adopted ):
Unique Method:
1. readLine () reads a row without a line break.
2. newLine () writes a line break.
Supplement: The difference between newLine and \ r \ n is that newLine is cross-platform, while \ r \ n is only applicable to Windows.
Java. util. Properties: an object that can store key values persistently (subclass of Hashtable)
Core IO stream code, copy
Public static void main (String [] args) throws IOException {FileInputStream FCM = new FileInputStream ("E: \ read.txt"); FileOutputStream fos = new FileOutputStream ("E: \ write.txt "); // int len; // byte [] arr = new byte [1024]; int B; // while (len = FCM. read (arr ))! =-1) {// fos. write (arr, 0, len); while (B = Fi. read ())! =-1) {fos. write (B);} FD. close (); fos. close (); System. out. println ("file copy Code ");}
File class (Omitted ):
Serialization:
It is to convert the java object in the memory into a platform-independent binary stream, so that it can be permanently stored on the disk.
The differences between Serializable and Externalizable interfaces are as follows:
1. The former has poor performance, but is simple and often used.
2. The latter has good performance, but increases programming complexity.
The transient keyword. After being modified, the default JVM serialization operation is not performed. After deserialization, the value of the transient variable is set to the initial value. For example, if the int type is 0, the object type is null.
The deserialization of java object must provide the class file of this object. With the upgrade of the project, how does java ensure the compatibility of the two class files?
The java serialization mechanism allows a private static final serialVersionUID value for the serialization class to identify the serialization version of the java class.
WriteObject and readObject methods:
1. during the serialization process, if the writeObject and readObject methods are defined in the serialized class, the virtual opportunity attempts to call the writeObject and readObject methods in the object class, perform custom serialization and deserialization.
2. If this method is not available, the defaultWriteObject method of ObjectOutputStream and the defaultReadObject method of ObjectInputStream are called by default.
3. The custom writeObject and readObject methods allow you to control the serialization process. For example, you can dynamically change the serialization value during the serialization process.
Note:
1. Reflection, serialization, and deserialization will damage the singleton design mode.
2. The object obtained through Singleton serialization and deserialization is a new object, which destroys Singleton.
3. Define the readResolve method in Singleton and specify the generation policy of the returned object in the method to prevent the Singleton from being damaged.