加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml

发布时间:2020-12-16 00:12:56 所属栏目:百科 来源:网络整理
导读:用jdom写xml文件 public class App { public static void main( String[] args ) throws Exception { OutputStream out = new FileOutputStream( "d:/customers.xml" ); Document document = new Document(); Element root = new Element( "customers" ); do

用jdom写xml文件


public class App



{


public static void main( String[] args ) throws Exception



{


OutputStream out = new FileOutputStream("d:/customers.xml");


Document document = new Document();


Element root = new Element("customers");



document.setRootElement(root);


for(int i=0;i<10;i++){


Element ec = new Element("customer");


Element namee = new Element("cname");


namee.addContent("fiona"+i);


Element passworde = new Element("password");


passworde.addContent("123"+i);


Element birthe = new Element("birth");


birthe.addContent("1992-10-1"+i);



ec.addContent(namee);


ec.addContent(passworde);


ec.addContent(birthe);


root.addContent(ec);


}


XMLOutputter outputter = new XMLOutputter();



outputter.setFormat(Format.getPrettyFormat());


outputter.output(document,out);


out.close();


}


}


??

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读