It’s a known fact that if a file is already in use, it cannot be modified by another process. In this scenario, when a program or process opens a file, the OS puts a lock on it, and if another program tries to modify it, it will not be allowed. This post will help you resolve the error where The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process
Now that you know why the program cannot access the file, it is time to figure out which process has already put a lock on them. The error could appear in any program like Visual Studio, Outlook, Windows Update, Photos App, Java, etc.
Before you read on, we recommend you restart your computer and then see if this makes the error go away.
If you do not want to restart, then to find out the lock, you will need to use Sysinternal Suite’s Process Explorer.
Launch the Process Explorer program and locate the icon that says, “Find Windows Process.” Drag the icon and drop it on the file, and it will instantly reveal the process.
Please right-click on the process and kill it.
Now, when you try to access the file with your program, it will not throw any error.
Fix Windows Update Code 0x80070020
When updating or upgrading Windows, if you get an error code 0x80070020, it means that files or resource required by the Windows Update process is being used elsewhere. The full error message says—
The existing process cannot access the file because it is being used by another process.
To fix this error, you will need to use the MSCONFIG tool to get the PC into a clean boot state and then try to update it again.
Fix Photos App Error 0x80070020
A similar error happens with the Photos App as well, where it cannot save the file because another process is using it. You may have to change the file name or save it to another location, and so on.
How to resolve the process Cannot access the file because it is being used by another process in Java?
To resolve The process cannot access the file error in Java, first ensure the file isn’t being accessed concurrently by your code. Utilize synchronized blocks or methods to manage concurrent access. If using a third-party library, check for proper usage and release of resources. Also, ensure the file isn’t open in another application before running your Java program. If necessary, use FileChannel or java.nio package to handle files more robustly.
It’s not a critical error and only restricts the modification of files. The chances are that if you restart the computer, it will fix the problem, but if you face this all the time, these tips will help you resolve the problem.