[SOLVED] Read/Write to same XML file
I wrote a program that uses a SAX parser to go through a document, replace a certain word with a user specified one, and then re-write it to the same file. The only problem is that I'm getting a
"SAXParseException: Premature end of file.Error: null"
error when I try to overwrite the current file.
I have:
FileReader file_in = new FileReader(arg[0]);
theReader.parse(new InputSource(file_in));
in my main program
but then in my actual parser class in order to write to the file I have
BufferedWriter out = new BufferedWriter(new FileWriter(filename,false));
I assumed that by giving the FileWriter the flag to overwrite that everything should work, alas I was wrong. The program works as it should if I do something like:
String newFile = "NEW" + filename;
and then pass it to FileWriter, but when it's reading/writing to the same file, it freaks out.
Any suggestions?