Java.io.IOException: Process cannot access the file because another process has blocked a part - when using IOUtils.copyLarge () on Windows
The problem stems from the specific line of code in this try block:
try {
fInputStream = new FileInputStream(path);
#thisLine byteCount += IOUtils.copyLarge(fInputStream, fOutputStream);
fileCount++;
}
The stack trace looks like this:
java.io.IOException: The process cannot access the file because another
process has locked a portion
of the file
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:233)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1719)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1696)
This looks like a Windows issue. Is there any Windows file I / O best practice (s) that may be missing?
+3
source to share
1 answer
Check if another process is running on the same file. On Windows follow this post to figure it out -> https://superuser.com/questions/399659/how-can-i-identify-what-application-is-using-a-given-file
It should run as soon as no other process is accessing the same file.
To make sure you can actually access the file, read the next section -> Java: Check if the file is open
0
source to share