Today try to read a TXT file in UTF-8 format as follows
12345
However, after each read to a string type, the output string length is always 6, and the first bit prints no space after the console.
After debugging the bytecode, it is found that in the byte stream after reading the file, the first three bits of bytes were
-17,-69,-65
After viewing the data, it was found that this is a special byte in the Utf-8 format. Any file file in the Utf-8 format will have these three bytes.
This situation can cause problems when the read string is intercepted.
For example, when reading the date format, the content is 2018-09-29 00:00:00, and I want to be 2018-09-29, can be converted by method substring.
S.substring (0,10)
But the result of the conversion was: 2018-09-2.
This is because three special bytes are converted to a string and a line of space is taken.
UTF-8 format txt file read byte top three bit issues