2

I'm trying to move a file from one dir to another in Java, but I got the following error message "The process cannot access the file because it is being used by another process."

How can I find out which process is using this file in Java ?

I'm on Win 7.

Frank
  • 29,646
  • 56
  • 159
  • 233

1 Answers1

1

If a command-line approach is viable, and you're on a Linux-like system, then lsof is your friend. There are about 10 gazillion flags for lsof, but for your needs, it should be as simple as:

lsof myfile

You should get output similar to the following:

COMMAND    PID    USER  FD   TYPE DEVICE  SIZE    NODE NAME
someprog   4660 foobar mem    REG  253,0 58400 4522314 myfile

EDIT

You say you're using Windows. I'm not familiar with Windows command-line tools. However, here's a question that may help: How can I determine whether a specific file is open in Windows?.

Community
  • 1
  • 1
Oliver Charlesworth
  • 260,367
  • 30
  • 546
  • 667