XML file is not updating using the jdom

早过忘川 提交于 2019-12-01 08:35:01

This is a relatively common problem with many applications, not just JDOM.

When you create a FileOutputStream, and write to it, you HAVE TO FLUSH IT AND CLOSE IT before exiting your program.

Change:

xmlOutput.output(doc, new FileOutputStream(new File("./src/Lexicon.xml")));

to be (using try-with-resources):

try (OutputStream fileout = new FileOutputStream(new File("./src/Lexicon.xml"))) {
    xmlOutput.output(doc, fileout);
}

or:

OutputStream fileout = new FileOutputStream(new File("./src/Lexicon.xml"));
xmlOutput.output(doc, fileout);
fileout.flush();
fileout.close();
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!