I have a little program using STAX which copy the content of a XML file to another. By the way, I discovered an enigmatic problem with XMLStreamWriter .
When I try to write many elements, the writing works. But when I try to write few elements, it doesn't works (the file is empty).
For example, this code works (3000 elements):
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(new FileOutputStream("toto.xml"));
writer.writeStartDocument();
for(int i = 0; i < 3000; ++i) {
writer.writeStartElement("toto");
writer.writeEndElement();
}
writer.writeEndDocument();
And this code doesn't work (50 elements):
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(new FileOutputStream("toto.xml"));
writer.writeStartDocument();
for(int i = 0; i < 50; ++i) {
writer.writeStartElement("toto");
writer.writeEndElement();
}
writer.writeEndDocument();
Have you any idea ?
writer.close();
;)典型的行为。
我今天也遇到过这个,但是writer.flush()
没有用,只有writer.close()
o_o
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.