标签:style blog io color os sp for strong 文件
xml读取异常Invalid byte 1 of 1-byte UTF-8 sequence
org.dom4j.DocumentException: Invalid byte 1 of 1-byte UTF-8 sequence. Nested exception: Invalid byte 1 of 1-byte UTF-8 sequence
出现这个问题是在我修改过xml文件后又重新保存后读取,文件出现这个问题,先看一下出现问题的代码
1 FileWriter fileWriter=new FileWriter(path);//path为文件路径 2 XMLWriter write=new XMLWriter(fileWriter); 3 write.write(document);//写入流 4 write.close();//关闭流
查看资料是说xml的编码问题,所以对代码进行修改,修改之后如下
1 FileOutputStream outputStream= new FileOutputStream(path); 2 OutputStreamWriter writer= new OutputStreamWriter(outputStream, "utf-8"); 3 4 XMLWriter write=new XMLWriter(writer,OutputFormat.createPrettyPrint()); 5 write.write(document); 6 write.close();
这样问题就完美解决了
Xml读取异常--Invalid byte 1 of 1-byte UTF-8 sequence
标签:style blog io color os sp for strong 文件
原文地址:http://www.cnblogs.com/liuwt365/p/4085729.html