• XML文件生成——借助JDOM


     1 import java.io.* ;
     2 import org.jdom.* ;
     3 import org.jdom.output.* ;
     4 public class DOMDemo {
     5     public static void main(String args[]) throws Exception {
     6         Element addresslist = new Element("addresslist") ;
     7         Element linkman = new Element("linkman") ;
     8         Element name = new Element("name") ;
     9         Element email = new Element("email") ;
    10         Attribute id = new Attribute("id","lxh") ;
    11         Document doc = new Document(addresslist) ;    // 定义Document对象
    12         name.setText("李兴华") ;
    13         name.setAttribute(id) ;    // 将属性设置到元素之中
    14         email.setText("mldnqa@163.com") ;
    15         linkman.addContent(name) ;    // 设置关系
    16         linkman.addContent(email) ;
    17         addresslist.addContent(linkman) ;
    18         XMLOutputter out = new XMLOutputter() ;
    19         out.setFormat(out.getFormat().setEncoding("GBK")) ;    // 表示的是设置编码
    20         out.output(doc,new FileOutputStream(new File("D:" + File.separator + "address.xml"))) ;
    21     }
    22 }

    要求在工程中引入jdom.jar

  • 相关阅读:
    在Unity3D中开发的Hologram Shader
    在Unity3D中开发的Toon Shader
    在Unity3D中开发的Dissolve Shader
    2017.2.26
    2017.2.21
    2017.2.20
    2017.2.19
    2017.2.18
    2017.2.17<转>
    2017.2.16 linux
  • 原文地址:https://www.cnblogs.com/hixin/p/4151635.html
Copyright © 2020-2023  润新知