51,412
社区成员
发帖
与我相关
我的任务
分享
。而是用代码二时则程序正常运行。public void addPerson(String name,int age,String phone) throws IOException {
File file = new File("/Users/wasim/Workspaces/MyEclipse 2016 CI/connectList/person.xml");
Document doc = null;
OutputStream out=null;
try {
out = new FileOutputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OutputFormat format = OutputFormat.createPrettyPrint();
try {
//---------------------------------------------
doc = XMLUtils.readXML();
if(doc==null)System.out.println("doc is null");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}public void addPerson(String name,int age,String phone) throws IOException {
File file = new File("/Users/wasim/Workspaces/MyEclipse 2016 CI/connectList/person.xml");
try {
//---------------------------------------------
doc = XMLUtils.readXML();
if(doc==null)System.out.println("doc is null");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Document doc = null;
OutputStream out=null;
try {
out = new FileOutputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OutputFormat format = OutputFormat.createPrettyPrint();public static Document readXML() throws IOException, DocumentException{
Document doc =null;
File XMLfile = new File("/Users/wasim/Workspaces/MyEclipse 2016 CI/connectList/person.xml");
SAXReader reader = new SAXReader();
try{
doc = reader.read(XMLfile);
}
catch(Exception e){
System.out.println("gg");
}
return doc;
}
}
