Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.io.IOException:进程无法访问该文件,因为另一个进程已锁定了部分-在Windows中使用IOUtils.copyragle()时_Java_Windows_File Io - Fatal编程技术网

java.io.IOException:进程无法访问该文件,因为另一个进程已锁定了部分-在Windows中使用IOUtils.copyragle()时

java.io.IOException:进程无法访问该文件,因为另一个进程已锁定了部分-在Windows中使用IOUtils.copyragle()时,java,windows,file-io,Java,Windows,File Io,问题源于此try块中的特定代码行: try { fInputStream = new FileInputStream(path); #thisLine byteCount += IOUtils.copyLarge(fInputStream, fOutputStream); fileCount++; } 堆栈跟踪如下所示: java.io.IOException: The process cannot access the file b

问题源于此try块中的特定代码行:

try {
            fInputStream = new FileInputStream(path);
#thisLine   byteCount += IOUtils.copyLarge(fInputStream, fOutputStream);
            fileCount++;
    }
堆栈跟踪如下所示:

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) 
Channels.newInputStream(fileChannel);

这似乎是Windows特有的问题。是否有某些特定于Windows的文件I/O最佳做法可能会丢失

检查其他进程是否正在访问同一文件。在Windows上,请按照此帖子进行操作->

只要没有其他进程访问同一个文件,它就会工作


<> P>为了确保你能真正访问文件,考虑阅读下面的主题->

< P>我已经通过前面创建的代码解决了这个问题<代码>文件频道< /Cord>对象.< /P>
FileChannel fileChannel = FileChannel.open(path, 
                   StandardOpenOption.READ,StandardOpenOption.WRITE);
然后我创建了
InputStream
对象,如下所示:

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) 
Channels.newInputStream(fileChannel);

它工作正常,不再发生异常。

有任何进程或线程访问同一文件吗?@primitiveType当然有。例外情况就是这么说的。