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 」.