调用java.nio.Files.copy时出现文件正在使用错误(Path source,Path target,CopyOption ... options)

时间:2016-03-07 14:56:21

标签: java nio

我有一个复制文件的方法:

public static void copyFiles(File source, File destination)
{
    try
    {
        destination.setWritable(true);
        Files.copy(source.toPath(), destination.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING,
            java.nio.file.LinkOption.NOFOLLOW_LINKS);
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}

但是我在调​​用此方法时遇到错误:

java.nio.file.FileSystemException: C:\analyticslogs\fsLogs.log: The process cannot access the file because it is being used by another process.
    at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
    at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
    at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
    at sun.nio.fs.WindowsFileCopy.copy(Unknown Source)
    at sun.nio.fs.WindowsFileSystemProvider.copy(Unknown Source)
    at java.nio.file.Files.copy(Unknown Source)
    at com.platform.module.analytics.util.FileOps.copyFiles(FileOps.java:1417)
    ... 14 more

我在这周围搜索并发现我的文件可以由我自己的程序保持打开状态。我保持任何资源开放还是一个不同的问题?

0 个答案:

没有答案