我正在尝试创建一个简单的 xml 文档。
我从来没有找到关于它的好文档,所以我只是这样尝试:
Element response = new Element("Artikelliste");
Element artikel1 = new Element("Artikel");
Element artikel2 = new Element("Artikel");
artikel1.setAttribute("nummer", "5678");
artikel1.setAttribute("bezeichnung", "KettenhandschuhXML");
artikel2.setAttribute("nummer", "1011");
artikel2.setAttribute("bezeichnung", "MesserXML");
response.addChild(artikel1);
response.addChild(artikel2);
OutputStream os = Storage.getInstance().createOutputStream("test1234.xml");
OutputStreamWriter writer = new OutputStreamWriter(os);
XMLWriter xmlWriter = new XMLWriter(false);
xmlWriter.writeXML(writer, response);
FileSystemStorage.getInstance().openOutputStream("test1234.xml").write(response.toString().getBytes());
IllegalArgumentException由于最后一行,我目前得到一个,它说:
test1234.xml 不是有效路径,使用 FileSystemStorage.getInstance().getAppHomePath() 获取有效的 dir 路径来读取/写入文件
如果我更正相应的行,它看起来像这样:
FileSystemStorage.getInstance().openOutputStream( FileSystemStorage.getInstance().getAppHomePath()).write (response.toString().getBytes());
但是程序无法知道是哪个文件??!当我像这样运行代码时,没有错误消息,也没有任何反应,也没有创建文档......
感谢帮助!:)