To use XMLStreamReader I am initializing it like -
XMLInputFactory f = XMLInputFactory.newInstance();
XMLStreamReader reader = f.createXMLStreamReader(new FileReader(
"somefile.xml"));
Iterating over it like -
if (reader.hasNext()) {
reader.next();
// do something with xml data
}
Finally closing it like -
reader.close();
This looks to be a normal flow but I am seeing some strange behavior. Even after closing reader, OS doesn't allow me delete/move the xml file unless I exit from java program. When run on Win2k8-server, I get error message saying java.exe is using this xml file.
So I have couple of questions -
- Do I need to explicitly close each FileReader's close?
- How can I find out which java code path is keeping this file handle open.
Looking @ the documentation of XMLStreamReader's close(), I get following - "Frees any resources associated with this Reader. This method does not close the underlying input source."
What is the meaning of "underlying input source"? Why is that not closed by reader's close()?