[英]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.