Encoding: the string is converted into a byte array.
Decoding: convert a byte array into a string.
String --> byte []; Str. getbytes ();
Byte --> string: New String (bytep []);
If an error occurs during encoding, give up.
If an error occurs during decoding, compile it once and solve it once (common method) [Use GBK for encoding to decode
This method does not work, UTF-8 will find similar words and the source code will change]
Enter the UNICOM character in the notepad, and the character will become garbled because the two characters are in the UNICOM encoding format.
Encoding Rules for UTF-8 compliance
Interfaces without methods are called Mark interfaces.
Fileoutputstream out;
Out. Write (256) only outputs the lowest 8 bits
Opening notepad is actually a process of decoding.
Objectinputstream and objectoutputstream
The operated object must implement serizlizable (Mark Interface); static final long serialversionuid = 42l;
Tags of the serizlizable Interface
Convert objects in heap memory
Therefore, static data cannot be serialized (also known as persistent storage ).
Transient cannot be serialized either.
Pipeline Flow:
Pipedinputstream and pipedoutputstream
Input and output can be directly connected by using
Randomaccessfile
Random access to files, with read/write methods.
Using skipbytes (intx) and seek (int x) to achieve Random Access
This class is not a subclass of the IO system.
Instead, it directly inherits from the object
But it is a member of the IO package because it has the Read and Write Functions.
An array is encapsulated internally and the array elements are operated through pointers.
You can use getfilepointer to obtain pointer information.
You can also use seek to change the pointer position.
In fact, the principle of Wencheng's read and write is that the byte input stream and the output stream are encapsulated internally.
The constructor shows that this class can only operate files.
If the mode is read-only R and no file is created, an existing file will be read. If the file does not exist
An exception occurs.
If the mode is RW, the operated file will be automatically created if it does not exist. If it exists, it will be created and will not be overwritten if it exists.
The seek method is used to adjust the pointer in the object. A. Write (INT) outputs the lowest 8 bits of the parameter,
Stream objects that can be used to operate on Basic Data Types
If datainputstream and dataoutputstream are writeutf, they can only be read in the corresponding method. Conversion stream not available, UTF-8 modified for writeutf
If it is a byte stream and saved in notepad, the system will select the encoding table for query, so it is garbled.
Operation Basic Data Type
Datainputstream and dataoutputstream
Operation byte array
Bytearrayinpustream and
Bytearrayoutputstream
Operator character array
Chararrayreader and chararraywrite
Operation string
Stringreader and stringwriter
Bytearrayinputstream: when constructing a data source, the data source must be a byte array.
Bytearrayoutputstream: you do not need to define the data purpose during the construction, because the object contains its own array with variable length, which is the data destination.
Because both stream objects operate on arrays and do not use system resources, close is not required.
Source device:
Keyboard System. In Hard Disk filestream memory arraystream
Target device:
Console System. Out Hard Disk filestream memory arraystream
Use stream ideas to operate Arrays
The computer can only identify binary data, and the early generation is an electrical signal.
To facilitate the application of computers and enable them to recognize texts in different countries, the texts in each country are represented by numbers.
And correspond to each other to form a table.
This is the encoding table.
ASCII: The American standard information interchange code can be expressed in seven bytes.
ISO8859-1: Latin code table, European code table, represented in 8 bits of a single byte
Gb2312: Chinese code table
GBK: Chinese encoding table upgrade, combining more Chinese characters and characters
UNICODE: A Chinese standard code that combines multiple types of texts;
UTF-8: represents a character in at most three bytes
In the middle, Unicode is passed. You can use it to test it.