Chinese resolution includes a coding error occurred xml Invalid byte 1 of 1-byte UTF-8 sequence

Due to: save operation is performed in a non-encoded format utf-8 of

1, the simplest is to <xml version = "1.0" encoding = "UTF-8"??> Changed to: a direct replacement for string; for files, <xml version = "1.0" encoding = "gbk"??> first read, replace, and finally resolved writeback
2, or to save the xml open when the character set to save the UTF-8
3, xml first re-write the code analysis again when
 SAXReader reader = new SAXReader (); 
  Document = reader.Read org.dom4j.Document ( "D: \\ ha.xml"); 
  the OutputFormat of the OutputFormat new new = (); 
  of.setEncoding ( "UTF-. 8"); // change the encoding 
  XMLWriter writer = new the XMLWriter (new new FileWriter "D: \\ dom4j.xml"), of); 
. 4, when read by the direct dom4j io read, modify the character encoding
the FileInputStream = new new in the FileInputStream (new new File (fileName));
Reader read = the InputStreamReader new new (in, "GBK");
the Document Document reader.Read = (Read);

5, there may appear to save utf-8 format still does not, at this time, can be resolved using org.w3c.dom.Document save.

Published 19 original articles · won praise 3 · Views 9773

Guess you like

Origin blog.csdn.net/pinghuqiuyue9/article/details/50949440