Skip to content
Advertisement

java Cannot delete file, being used by another process

I have this code

JavaScript

and when I execute it it says

java.nio.file.FileSystemException
The process cannot access the file because it is being used by another process (in sun.nio.fs.WindowsException)

In the sameSha1() I have this:

JavaScript

I want to delete the file ‘SHA1.txt’. How can I do this?

Advertisement

Answer

I guess with sameSha1 you open SHA1.txt to read it and you forget to close it.

EDIT:

From your comment you contain the following line in sameSha1:

JavaScript

So you create a scanner instance but you don’t explicitly close it. You should do something like that:

JavaScript

Or as @HuStmpHrrr suggests in Java 7:

JavaScript
Advertisement