dom4j 输出UTF-8 XML时中文乱码
2013-05-23 20:49
411 查看
使用DOM4J的XMLWriter输出UTF-8编码的XML文件时,出现乱码。
首先,设置输出的编码,在这我们使用UTF-8:
Java代码 :
输出代码:
Java代码 :
上面的输出如果有中文,可以会出现乱码的问题,将上面的FileWriter改成FileOutputStream便可以了。
Java代码
原文链接地址:http://royboy.iteye.com/blog/337948
首先,设置输出的编码,在这我们使用UTF-8:
Java代码 :
OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("utf-8");
输出代码:
Java代码 :
try { output = new XMLWriter(new FileWriter("entity.xml"), format); output.write(document); output.close(); } catch (IOException e) { e.printStackTrace(); }
上面的输出如果有中文,可以会出现乱码的问题,将上面的FileWriter改成FileOutputStream便可以了。
Java代码
try { output = new XMLWriter(new FileOutputStream("entity.xml"), format); output.write(document); output.close(); } catch (IOException e) { e.printStackTrace(); }
原文链接地址:http://royboy.iteye.com/blog/337948
相关文章推荐
- dom4j 输出UTF-8 XML时中文乱码
- 【原创】JDom输出UTF-8的XML完美解决(中文乱码的原因分析)
- JDom输出UTF-8的XML出现中文乱码完美解决
- dom4j解析utf-8 的xml出现中文乱码的为
- utf-8编码引起js输出中文乱码的解决办法
- 用dom4j建立,修改XML文档,并解决格式化输出和中文问题
- utf-8编码引起js输出中文乱码的解决办法
- dom4j 输出xml时乱码问题
- 用dom4j建立,修改XML文档,并解决格式化输出和中文问题
- php输出UTF-8格式XML文件中文乱码问题(含asp,asp.net,jsp代码)
- UTF-8编码导致JS输出中文乱码
- dom4j建立,修改XML文档,并解决格式化输出和中文
- 【转载】utf-8编码引起js输出中文乱码的解决办法
- dom4j建立,修改XML文档,并解决格式化输出和中文【转】
- 用dom4j创建xml(中文不会乱码)
- (转)J2me控制台中文输出乱码问题,XML解析中文乱码问题
- php输出UTF-8格式XML文件中文乱码问题(含asp,asp.net,jsp代码)
- UTF-8编码导致JS输出中文乱码
- 关于gcc编译后的带中文输出的utf-8的c文件输出乱码问题
- MFC/C++ CFile写入文件数据,输出utf-8的文本。(防止中文乱码)