48

I tried to delete a file that I have two of, one slightly changed, so I could delete the older one and replace it with the new one I changed. When I tried to delete the file I got the error message 'file in use' where it said the action can't be completed because the file is open in Java(TM) Platform SE binary.

How do I close it?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user1642596
  • 481
  • 1
  • 4
  • 3
  • 2
    check if a java process is running - if its holding onto a file lock, you might want to kill the java process (I am assuming this is a test box you are using and not some production server). – ali haider Sep 03 '12 at 02:20

7 Answers7

93

This is what worked for me (using Windows). It is basically the same procedure as commented by ali haider, but with more details...

Using Windows command prompt:

tasklist | findstr java

("findstr" is a command line utility for Windows similar to "grep" in Linux)

Search for any lines with 'java' and note the PID of the java process.

taskkill /F /PID "PID_OF_JAVA_PROCESS"

where "PID_OF_JAVA_PROCESS" should be replaced with actual PID number.

Result:

SUCCESS: The process with PID "PID_OF_JAVA_PROCESS" has been terminated.

Repeat for each java process that is running. Now you should be able your desired file!

Let me know if you need instructions for Linux (i.e. ps, kill, etc.), but probably most Linux users know these...

evaldeslacasa
  • 582
  • 6
  • 17
robguinness
  • 16,266
  • 14
  • 55
  • 65
  • This worked for me, on Windows 10. I would usually go to Task Manager and end the process. But this time it wasn't present in the Task Manager processes either. – Obaid Aug 30 '20 at 06:05
  • 2
    Much easier to just do: `taskill /im java.exe /f`. Achieved the exact same result for me – Recessive Nov 11 '22 at 13:53
  • 1
    @Recessive just a typo in your command - `taskkill /im java.exe /f` – was_777 Mar 17 '23 at 10:32
28

Simply open the task manager on Windows, Check for Processes, Close all the java processes. Now again try deleting the file, you should be able to. This worked for me.

Cheers!

Saps
  • 281
  • 3
  • 2
  • did not work for me, whenever i was deleting the java process another java process was immediately created and it was taking 1 gb of memory, instead, I restarted the windows and problem was solved – Akshay Vijay Jain Mar 18 '16 at 14:54
4

Close the project in Eclipse and it should work.

Cristik
  • 30,989
  • 25
  • 91
  • 127
Hitesh Shekhada
  • 377
  • 1
  • 2
  • 9
3

In Windows 8.1:

1) Start Menu...choose "Run" and type: msconfig and click "OK".

2) "System Configuration" opens click the "Startup" tab.

3) Click where it says "Open Task Manager".

4) Choose the "Processes" tab.

5) Look through the list and find "Java SE". Right click and choose "End Task".

6) Close "Task Manager" and "System Configuration" box.

7) Go back to file that could'nt be deleted. Right click and choose "Delete" again. Presto........file deleted.

bern1wv
  • 31
  • 1
3
  1. Open Task Manager in windows.
  2. Go to view-> Select Columns and check command line.
  3. Now kill the java process that locked the file. (command line option shows the path of the java proces from where it gets executed so that unnecessarily you don't need to kill all the java process.)
V_Dev
  • 83
  • 6
  • did not work for me, whenever i was deleting the java process another java process was immediately created and it was taking 1 gb of memory, instead, I restarted the windows and problem was solved – Akshay Vijay Jain Mar 18 '16 at 14:53
  • Update: I didn't see a View option for Select Columns but you can right-click on the tab and it's one of the options. Thanks! – Hugh Seagraves Jul 20 '23 at 19:02
2

If it's not something that runs during a system boot, try rebooting to clear all open files.

AWT
  • 3,657
  • 5
  • 32
  • 60
  • 6
    One would assume there is some other solution than rebooting (which is annoying for simply closing an open file)! – robguinness Feb 14 '13 at 10:52
1

-Open Task Manager -Go Details Tab -Find Name=java.exe and CommandLine= your jar path -Right Click -End Task

Example: Name Command line
javaw.exe "C:\Program Files\Java\jdk-11.0.2\bin\javaw.exe" -jar "C:\TEST\0.0.1-SNAPSHOT.jar"

Harun ÇETİN
  • 81
  • 1
  • 4