dom4j生成的xml文件 中文是乱码

2025-01-03 14:18:44
推荐回答(1个)
回答1:

将PrintWriter pw=new PrintWriter(f);换成dom4j里的输出流
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("utf-8");
format.setIndent(" ");
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(f));
XMLWriter writer1 =new XMLWriter(format);
writer1.write(dom);希望对你有用!