[IO stream in Java]Category:1. Depending on the direction of the stream: the input stream and the output stream are based on the size of the read text: byte stream and character stream; bytes are read in bits, characters are garbled when reading Chinese, and character streams are read by characters, which is commonly used to read Chinese. Depending on how it is read: node stream and cache stream[Bufferedinputstream and .... Output:]Creates a new object, passing in a file, which acts as a cache stream.can reduce the number of files read and write, improve read and write speed. Program Finally, flush the cache stream: Bos.fluse (); The buffers must be closed! Bis.close (); Bos.close ();(automatically refreshes the cache stream) the role of the cache stream: Pass the file object as a parameter to the cache object. This notation, which we call the IO chain, only needs to close the outermost stream when IO is closed, and the inner laminar flow will automatically close.[DataInputStream class]Binary file read and write operation, (can read and write binary files, basic FIS Read and write may be garbled). The basic data types in Java can be read and written directly compared to the basic stream. (Files written using DataOutputStream can only be read using the DataInputStream) method. readUTF (); Read Chinese.[ObjectInputStream]1. The same as the basic flow, you can use read and writer read and write directly; 2. As with DataInputStream, you can read and write directly to the Java basic data type. method. Redaint (); Readdouble (); 3. Using ReadObject () and writeobject () can be used to read and write to an object. When reading and writing objects, be sure to serialize the object classes to read and write. [Serialization and deserialization of objects] concept: Serialization of objects: the process of persisting objects in a program, persisted in a file. Object deserialization: The object that is saved in the file is re-read to the procedure in the program. Serialization must be an object to which the class must implement the Serializable interface when an entity class implements a serializable interface, it can settle a serialized version number idprivate static final long serialversionuid = 1L; An object that can represent the serialization and deserialization operations with an ID, which is the same object. Otherwise, after serialization, if the entity class attributes are truncated, the system defaults to not the same class when serializing, causing an error.[character Stream]1. When processing a data unit, a character is used as the unit, while a byte stream is used as a unit. 2. The base class of the characters: Reader and writer are abstract classes FileReader and FileWriter are the two basic character streams that directly inherit the word abstract class. 3.FileReader and FileWriter can only use the encoding format used by the system, unable to specify the encoding, if the file format is different from the system default format, then using both methods to read and write will cause Chinese garbled.[InputStreamReader and OutputStreamWriter]1. Convert the byte stream to a character stream, and support the encoding format of the custom read and write; The file comes in with the cache function. 2. Common encoding format. ASCII: American Standard message Code; ISO8859-1: European code; GB2312: GB code; GBK: GB extension code; ANSI code, can be divided into many kinds; English: GB2312; GBk; Traditional Chinese: BIG-5; Unicode encoding: International standard Code, compatible with most of the country's encoding format. Can be divided into utf-6,utf-8,utf-16.
Getting Started with Java article sixth: I/O flow