XML编码
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding(“UTF-8”);
XMLWriter writer = new XMLWriter(new FileOutputStream(XmlPath), format);
writer.write(doc);
writer.close();
保证输出的xml格式话,同时输出没有自动转换为ANSI。
如使用XMLWriter writer = new XMLWriter(new FileWriter(new File(XmlPath)), format);会出现Xml文件第一行是UTF-8,但是内容确实ANSI的乱码
【Java】XML编码
原文地址:https://www.cnblogs.com/defineconst/p/13410420.html