public UserDao() {
SAXReader saxReader = new SAXReader();
file = new File("G:/temp/diary/users.xml");
if(!file.exists()){
doc = DocumentHelper.createDocument();
doc.addElement("Users");
write();
}
else{
try {
doc = saxReader.read(file);
} catch (DocumentException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
private void write(){
try{
OutputFormat format = OutputFormat.createPrettyPrint();
//format.setEncoding("UTF-8");
format.setNewlines(true);
XMLWriter output = new XMLWriter(new FileWriter(file),format);
output.write(doc);
output.close();
}catch(Exception e2){}
}