`
l120974020
  • 浏览: 58351 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

java写XML文件

 
阅读更多

JAR包:jdom.jar

Element license_write_root = null;
Document license_write_doc = null;

license_write_root = new Element ("根节点名称");  //创建License文件的根节点
license_write_doc = new Document(license_write_root);

Element license_fileHeader = new Element("子节点名称"); 
license_fileHeader.setAttribute("属性name","属性值"); //增加属性


license_write_root.addContent(license_fileHeader);  //添加子节点

//输出有格式的XML文件
XMLOutputter XMLOut = new XMLOutputter();
Format format = Format.getPrettyFormat(); // 格式化文档
format.setEncoding("UTF-8"); // 设置编码格式为utf-8  
XMLOut.setFormat(format);  
XMLOut.output(license_write_doc, new FileOutputStream("文件输出路径"));
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics