Invalidbyte1of1-byteUTF-8sequence solution

Source: Internet
Author: User
Error prompt: Invalidbyte1of1-byteUTF-8sequence cause analysis: in the Chinese version of the window java default encoding for GBK, that is, although we identified to save xml as ut... Error message:Invalid byte 1 of 1-byte UTF-8 sequence

Cause analysis:In Windows of the Chinese version, java is encoded as GBK by default, that is, although we have identified that we want to save xml in UTF-8 format, the files are actually saved in GBK format, so that is why we can use GBK, GB2312 encoding to generate xml files can be correctly parsed, and files generated in UTF-8 format cannot be parsed by the xml parser.

Change the xml encoding attribute value UTF-8 to UTF8, org. xml. sax. SAXParseException: Content is not allowed in trailing section, and resolve the problem with the string trim.

Solution:

1. the simplest is Change

2, or when the xml open another save the character set to UTF-8 save or change the program, the code is as follows:

SAXReader reader = new SAXReader (); org. dom4j. document document = reader. read ("D: ha. xml "); OutputFormat of = new OutputFormat ();. setEncoding ("UTF-8"); // change the encoding method XMLWriter writer = new XMLWriter (new FileWriter "d: dom4j. xml "), );

The eclipse editor can be changed in Eclipse as follows. in the eclipse Menu [Project] → [Properties],? [Resources], right? Text file encoding, set the original? Why ?? ??, Change? 「 UTF-8 」.

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.