我正在尝试在 XML 文件中编写一些 XML 行。但是,我只能在文件不存在的情况下这样做,因为如果它存在,我将覆盖信息。
这是我的代码:
public void writeToXMLSimulation() throws IOException {
File f = new File("Simulation_" + pt.ipp.isep.gecad.masgrip.MASGriP_GUI.getContainerNameTxt().getText() + "_Details.xml");
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
XMLWriter xmlWriter = null;
if (!f.exists()) {
try {
xmlWriter = new XMLWriter(new OutputStreamWriter(
new FileOutputStream(f), "UTF8"),
format);
xmlWriter.write(configs.XMLwriterDOM4J.createXMLDocumentForSimulations(jLabelAL, jTextFieldAL, id));
} finally {
if (xmlWriter != null) {
xmlWriter.flush();
xmlWriter.close();
}
}
} else {
try {
//I NEED SOMETHING HERE TO GET ME TO THE LAST LINE OF FILE
xmlWriter.write(
configs.XMLwriterDOM4J.createXMLDocumentForSimulations(
jLabelAL, jTextFieldAL, id));
} finally {
if (xmlWriter != null) {
xmlWriter.flush();
xmlWriter.close();
}
}
}
}
我该怎么做才能让我的代码写在最后一行之后?(不覆盖)
谢谢