UTF-8 format txt file read byte top three bit issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.