Utf-8 + Bom encoding causes read data part exceptions, utf-8bom

Source: Internet
Author: User

Utf-8 + Bom encoding causes read data part exceptions, utf-8bom

This is often the case in projects. Configure the corresponding relationship in the configuration file, and read data from the project at startup and save it to the map cache, in this way, you can directly find the corresponding ing from the map.

Then we encountered such a strange problem. A simple ing relationship is as follows:

1: "Chinese" 2: "Mathematics" 3: "English"

The ing relationship of the first line of Chinese cannot be obtained in any way. In debug, we can see that there is actually a ing relationship of 1: "Chinese" in map, but it cannot be obtained. this is very strange. There is no problem with the ing relationship of 2 or 3. If the ing relationship of 1 fails, null is returned. debug is used for debugging. I can't see the problem at all. I did not solve the problem by opening the key in the map. I found that the key of this 1 is a bit different, 2 and 3 can be a char corresponding to 2 or 3, but the key of 1 corresponds to 2 char, one is 1, however, before 1, another char was saved as \ ufeff. Baidu once found this \ ufeff was due to UTF-8 + bom encoding, which belongs to the bom header. this problem is clear. In fact, the bom header is also saved as the key part during map storage, resulting in the wrong value of the key in the first line, the value cannot be obtained.

The solution is clear. You only need to save the configuration file as UTF-8 encoded.

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.