To use XMLStreamReader, I initialize it as -
XMLInputFactory f = XMLInputFactory.newInstance(); XMLStreamReader reader = f.createXMLStreamReader(new FileReader( "somefile.xml"));
Iterate over it like -
if (reader.hasNext()) { reader.next(); // do something with xml data }
Finally closing it like -
reader.close();
This looks like a normal flow, but I see strange behavior. Even after closing the read, the OS does not allow me to delete / move the xml file unless I exit the java program. When starting up on the Win2k8 server, an error message appears: java.exe uses this XML file.
So, I have a couple of questions -
- Do I need to explicitly close each FileReader file?
- How to find out which java code path this file descriptor supports.
Looking at the XMLStreamReader documentation close (), I get the following: "Releases any resources associated with this Reader. This method does not close the underlying input source."
What is the meaning of the "main input source"? Why is this not closed by the reader close ()?
source share