开发者

XMLEvent.writeAsEncodedUnicode

I've bumped on to an strange issue. I'm trying to use stax to parse and save modified xml file but while everything works in Windo开发者_运维技巧ws - i get an empty file in Linux. I`ve seen only one post on springfourms about this issue but with no answer. So did anybody had the same problem ?

Sample code below:

FileWriter fileWriter = new FileWriter("/home/user/test.xml");

/* SOME CODE */

while (eventReader.hasNext()) {
    XMLEvent event = eventReader.nextEvent();
    switch (event.getEventType()) {
        case XMLEvent.START_ELEMENT: {
            event.asStartElement().writeAsEncodedUnicode(fileWriter);


Have you flushed and closed the FileWriter afterwards? If not, it could be a buffering issue.

(Personally I'd use an OutputStreamWriter wrapped around a FileOutputStream, instead of FileWriter, as the latter doesn't let you specify the file encoding...)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜