xml文件的保存

前面介绍了xml文件的加载,今天写写xml方面的保存,其实很简单,一般应用如下:

try
{
   OutputFormat format = OutputFormat.createPrettyPrint();
   format.setEncoding("GB2312");
   XMLWriter writer = new XMLWriter(new FileWriter(new File(filePathName)),format);
   writer.write(doc);
   writer.close();
}
catch(Exception ex)
{
   ex.printStackTrace();
}

filePathName,指出了文件路径和文件名称,如:d://a//b.xml;doc即document对象,这一点以后会讲到。

 

你可能感兴趣的:(xml,技术)