更新时间:2023-12-03 12:45:22
这是许多应用程序的一个相对常见的问题,而不是只是JDOM。
This is a relatively common problem with many applications, not just JDOM.
当你创建一个FileOutputStream并写入它时,你 必须冲它并关闭它 退出程序之前。
When you create a FileOutputStream, and write to it, you HAVE TO FLUSH IT AND CLOSE IT before exiting your program.
更改:
xmlOutput.output(doc, new FileOutputStream(new File("./src/Lexicon.xml")));
(使用try-with-resources):
to be (using try-with-resources):
try (OutputStream fileout = new FileOutputStream(new File("./src/Lexicon.xml"))) {
xmlOutput.output(doc, fileout);
}
或:
OutputStream fileout = new FileOutputStream(new File("./src/Lexicon.xml"));
xmlOutput.output(doc, fileout);
fileout.flush();
fileout.close();