WitchMan
WitchMan

Reputation: 11

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 Windows - 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);

Upvotes: 1

Views: 710

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1502016

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...)

Upvotes: 1

Related Questions