将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);希望对你有用!