简体   繁体   English

java.nio.file.FileSystemException:进程无法访问该文件,因为它正被另一个进程使用

[英]java.nio.file.FileSystemException: The process cannot access the file because it is being used by another process

I'm writing a program that copy themselve at first execution to a specific folder, working in linux or windows.我正在编写一个程序,在第一次执行时将它们自己复制到特定文件夹,在 linux 或 windows 中工作。
In linux it works perfectly but when I try to do the same on windows i get the following error:在 linux 中它工作得很好,但是当我尝试在 windows 上做同样的事情时,我收到以下错误:

java.nio.file.FileSystemException: The process cannot access the file because it is being used by another process (in sun.nio.fs.WindowsException) java.nio.file.FileSystemException:进程无法访问该文件,因为它正被另一个进程使用(在 sun.nio.fs.WindowsException 中)

So, the other process is the program itself, what should I use to skip this error?那么,另一个进程是程序本身,我应该用什么来跳过这个错误?

My code lines are:我的代码行是:

public void installProgram (){
    System.out.println("Doing Install...");
    File fileToBeInstalled = new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());

     try {
        Files.move(fileToBeInstalled.toPath(), installPathFile.toPath(), REPLACE_EXISTING);
     } catch (IOException ex) {
        MainClass.getMainClass(InstallerLinux.class.getName()).log(Level.SEVERE, null, ex);

    }
} 

Thanks!谢谢!

Ok, I don't found a perfect solution but something...好吧,我没有找到完美的解决方案,但有些东西......

try {
        //Files.move(fileToBeInstalled.toPath(), installPathFile.toPath(), REPLACE_EXISTING);
        Files.copy(fileToBeInstalled.toPath(), installPathFile.toPath(), REPLACE_EXISTING);
        fileToBeInstalled.delete();
} catch (IOException ex) {
    MainClass.getMainClass(InstallerLinux.class.getName()).log(Level.SEVERE, null, ex);

}

This copy correctly the file and erases correctly the original only on linux execution.此文件正确复制并仅在 linux 执行时正确擦除原始文件。

I think for do that I need to invoke the class using a class loader..我认为为此我需要使用类加载器调用类..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 此进程无法访问该文件,因为 KOTLIN 中的另一个进程 (java.nio.file.FileSystemException) 正在使用该文件 - This process cannot access the file because the file is being used by another process (java.nio.file.FileSystemException) in KOTLIN java.nio.file.FileSystemException 进程无法访问该文件,因为它正被另一个进程使用 - java.nio.file.FileSystemException The process cannot access the file because it is being used by another process java.nio.file.FileSystemException:无法访问该文件,因为它正由另一个进程使用 - java.nio.file.FileSystemException : cannot access the file because it is being used by another process java.nio.file.FileSystemException: C:\test.csv -> C:\test2.csv: The process cannot access the file because it is being used by another process in java - java.nio.file.FileSystemException: C:\test.csv -> C:\test2.csv: The process cannot access the file because it is being used by another process in java java.nio.file.FileSystemException: C:\p12\dummy.p12: 该进程无法访问该文件,因为它正被另一个进程使用 - java.nio.file.FileSystemException: C:\p12\dummy.p12: The process cannot access the file because it is being used by another process readAllBytes()。 FileSystemException:该进程无法访问该文件,因为它正在被另一个进程使用 - readAllBytes(). FileSystemException: The process cannot access the file because it is being used by another process java - 该进程无法访问该文件,因为它正被另一个进程使用 - java - The process cannot access the file because it is being used by another process Files.move(...) 抛出 FileSystemException:进程无法访问该文件,因为它正被另一个进程使用 - Files.move(...) throwing FileSystemException: The process cannot access the file be cause it is being used by another process 进程无法访问文件,因为它正在被另一个进程使用 - process cannot access file because it is being used by another process 该进程无法访问该文件,因为它正被另一个进程使用 - The process cannot access the file because it is being used by another process
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM