使用Jdom从java创建xml
我正在使用这段代码创建生成的XML。xml文件
Element FICHADAS = new Element("FICHADAS");
Document doc = new Document(FICHADAS);
doc.setRootElement(FICHADAS);
Element fichada = new Element("fichada");
fichada.addContent(new lement("N_Terminal").setText("XX"));
fichada.addContent(new Element("Tarjeta").setText("XX"));
fichada.addContent(new Element("Fecha").setText("XX"));
fichada.addContent(new Element("Hora").setText("XX"));
fichada.addContent(new Element("Causa").setText("XX"));
doc.getRootElement().addContent(fichada);
XMLOutputter xmlOutput = new XMLOutputter();
xmlOutput.setFormat(Format.getPrettyFormat());
xmlOutput.output(doc, new FileWriter("generatedXml.xml"));
但我在最后一行中遇到了一个错误(我使用的是eclipse):
Multiple markers at this line - Unhandled exception type IOException - Unhandled exception type IOException
# 1 楼答案
你的方法应该是
throw
这个IOException
,或者你必须在代码周围使用try-catch-block
或者