java xml parser keeps file locked after SAXException
Part of my program contains the below code to parse an xml file using standard java classes. My interest is in the blue part at the end where the code is doing the actual parsing.
Please note that I'm quite new to java and OOP, so there might be something very obvious that I have overlooked. Code:
DocumentBuilderFactory factory; When I run the program in WindowsXP, I've found that the xml file is locked for writes by the parser and the lock is not released when the error occurs. At this stage I must close the java application to clear the lock. So I'm looking for a way to remove the lock. Any advice? PS The editor that I use for editing the file tells me that the file is in use when I try to save the file. |
Not sure if this is related to your problem, but it would explain it:
http://bugs.sun.com/bugdatabase/view...bug_id=6359560 Essentially, Windows keeps a lock on memory mapped files even after you have closed them. Which makes memory mapped files useless on Windows. It's feasible that the XML parser implementation that you're using uses memory mapped files to read the file in. You could try using a different XML parser implementation and seeing if that works. |
Thanks for the reply. I'm not 100% sure if it's the same (kind of) problem. I think that in that case windows would also keep the lock when a file is succesfully parsed.
I have posted the question on the sun forums as well and will see what will happen. |
Just in case some one, like me, finds this thread searching for an answer to this question.
Here is my solution: instead of Code:
try { Code:
InputStream stream = null; |
All times are GMT -5. The time now is 02:27 PM. |