1.建立一个xml文件
public class XML{
public Document createXML(){
Element root=new Element("Book");
Document doc=new Document(root);
Element name= new Element("name");
name.addContent("java");
root.addContent(name);
return doc;
}
public static void main(String[] args){
XML xml=new XML();
doc1=xml.createXML();
XMLOutputter outp1 = new XMLOutputter(" ",false,"GBK");
outp1.output(doc1, new FileOutputStream("filename.xml"));
}
}filename.xml如下
<?xml version=1.0 charset="GBK">
<Book>
<name>Java</name>
</Book>
public class XML{
public Document createXML(){
Element root=new Element("Book");
Document doc=new Document(root);
Element name= new Element("name");
name.addContent("java");
root.addContent(name);
return doc;
}
public static void main(String[] args){
XML xml=new XML();
doc1=xml.createXML();
XMLOutputter outp1 = new XMLOutputter(" ",false,"GBK");
outp1.output(doc1, new FileOutputStream("filename.xml"));
}
}filename.xml如下
<?xml version=1.0 charset="GBK">
<Book>
<name>Java</name>
</Book>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货