File remains in use after calling close

D

dmitryr

I observed very strange problem, when I open a file using new
FileInputStream() and then close this stream, and then try to delete or
rename it OS Windows reports:
The process cannot access the file because it is being used by another
process.
It happens only after several open/close cycles.
Stream closing happens in finally so can't be bypassed. For surety I've
added counter of all open/close and it remains 0. Is any debug methods
how to figure which object in Java keeps a stream opened? One more
detail, a stream can be obtained using connection getInputStream,
however it get closed anyway.
 
B

Betty

I observed very strange problem, when I open a file using new
FileInputStream() and then close this stream, and then try to delete or
rename it OS Windows reports:
The process cannot access the file because it is being used by another
process.
It happens only after several open/close cycles.
Stream closing happens in finally so can't be bypassed. For surety I've
added counter of all open/close and it remains 0. Is any debug methods
how to figure which object in Java keeps a stream opened? One more
detail, a stream can be obtained using connection getInputStream,
however it get closed anyway.

I notice this on my WIN XP Pro box. I can't delete a file.
What does work is
f.deleteOnExit();
 
A

Adam P. Jenkins

I observed very strange problem, when I open a file using new
FileInputStream() and then close this stream, and then try to delete or
rename it OS Windows reports:
The process cannot access the file because it is being used by another
process.
It happens only after several open/close cycles.
Stream closing happens in finally so can't be bypassed. For surety I've
added counter of all open/close and it remains 0. Is any debug methods
how to figure which object in Java keeps a stream opened? One more
detail, a stream can be obtained using connection getInputStream,
however it get closed anyway.

I don't know the solution, but I've encountered this same problem on
Windows, where I know I've closed a FileInputStream or FileOutputStream,
but Windows still says it's open and can't be deleted until I exit the
Java app. I assume it's a bug in Sun's java.io library on Windows.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top