JAVA- base (stream buffer - commutations - serialized stream)

JAVA- base (stream buffer - commutations - serialized stream)

1. The buffer flow?

Buffered stream, also known as high flow, is four basic FileXxxenhancement stream, the stream is 4

Byte stream buffer : BufferedInputStream,BufferedOutputStream

 

Character buffer stream : BufferedReader,BufferedWriter

2. Principle?

When you create a stream object, it creates a built-in buffer array default size of the buffer by reading and writing, to reduce the number of system IO, thereby improving the efficiency of reading and writing.

300M copy of a file, the likely rate of flow in the normal io 20 minutes, the buffer flow only a few hundred milliseconds.

3. The constructor?

public BufferedInputStream(InputStream in) : Create a new buffered input stream.

 

public BufferedOutputStream(OutputStream out): Creates a new buffered output stream.

public BufferedReader(Reader in) : Create a new buffered input stream.

public BufferedWriter(Writer out): Creates a new buffered output stream.

4. The method?

BufferedReader: public String readLine(): read a line of text.

BufferedWriter,: public void newLine(): writing a line line separator, the symbol is defined by the system property.

5. commutations?

According to certain rules, the character is stored in the computer, called encoding .

Binary number stored in the computer according to certain rules resolve displayed, called decoding .

In IDEA, a FileReadertext file read in the project. Because IDEA settings are the default UTF-8encoding, so there is no problem. However, when reading text files created in the Windows system, because the default Windows GBK coding system that will be garbled.

 

6.InputStreamReader?

It is a subclass of Reader, is a character stream flowing from the byte bridge. It reads bytes using the specified character set and decodes it into a character.

7. constructor?

InputStreamReader(InputStream in): Use the default character set to create a stream of characters.

InputStreamReader(InputStream in, String charsetName): Create a character set specified character stream.

8.OutputStreamWriter?

Commutations java.io.OutputStreamWriter, is a subclass of Writer, the bridge is the byte stream flowing from the character. Using the specified character set byte character encoding.

9. constructor?

OutputStreamWriter(OutputStream in): Use the default character set to create a stream of characters.

OutputStreamWriter(OutputStream in, String charsetName): Create a character set specified character stream.

10. serialization?

Java provides an object serialization mechanism. An object may be represented by a sequence of bytes, the byte containing the sequence 对象的数据, 对象的类型and 对象中存储的属性other information. After a sequence of bytes written to the file, the file corresponding to persist information about an object.

Conversely, the byte sequence can also be read from a file back, rearranged, performed deserialized . 对象的数据, 对象的类型And the 对象中存储的数据information can be used to create objects in memory

11.ObjectOutputStream?

java.io.ObjectOutputStream Class, the primitive data types Java objects written to a file, lasting storage object.

 

12. constructor?

public ObjectOutputStream(OutputStream out): Creating a specified OutputStream of ObjectOutputStream.

To serialize an object, it must meet two conditions:

1 class must implement the java.io.Serializableinterface Serializableis a marker interface, the class does not implement this interface will not cause any state serialization or deserialization, will be thrown NotSerializableException.

 

2 all the attributes of the class must be serializable. If a property does not need to be serialized, then the property must be marked transient, using transientthe keyword modifications.

public final void writeObject (Object obj) : Write the specified object.

13.ObjectInputStream?

ObjectInputStream deserialization stream, prior to use of the original data sequence ObjectOutputStream restore objects.

14. constructor?

public ObjectInputStream(InputStream in): Create an InputStream of ObjectInputStream specified.

public final Object readObject () : Reads an object.

For the JVM can deserialize object, it must be able to find the class class files. If you can not find this type of class file, then throw an ClassNotFoundExceptionexception.

Guess you like

Origin www.cnblogs.com/fan123yh/p/11029654.html