写入XML文件

public static void writeXMLFile(Document doc,String xmlFileName) throws IOException{
  OutputFormat format = OutputFormat.createPrettyPrint();// 创建文件输出的时候,自动缩进的格式                 
  format.setEncoding("UTF-8");//设置编码
  //文件生成的地址
  XMLWriter writer = new XMLWriter(new FileWriter("f:\\createFile\\"+xmlFileName),format);
  //写入文件
  writer.write(doc);
  writer.close();
 }

posted @ 2017-01-10 19:57  bake056  阅读(148)  评论(0编辑  收藏  举报