public class Demo2 {
/**
* @param args
*/
public static void main(String[] args) throws Exception{
Document doc = new SAXReader().read(new File("./src/contact.xml"));
//指定文件输出的位置
FileOutputStream out = new FileOutputStream("c://bea//xml//contact.xml");
OutputFormat format = OutputFormat.createCompactFormat(); //紧凑的格式.去除空格换行.项目上线的时候
//OutputFormat format = OutputFormat.createPrettyPrint(); //漂亮的格式.有空格和换行.开发调试的时候
format.setEncoding("utf-8");
//1.创建写出对象
XMLWriter writer = new XMLWriter(out,format);
//2.写出对象
writer.write(doc);
//3.关闭流
writer.close();
}
}
dom4j写出项目下的文档到硬盘指定路径下
最新推荐文章于 2022-10-10 11:08:53 发布