2016-05-03 34 views
0

當需要更新時,我需要重寫jar文件。爲了反駁它,我做了以下操作:如何重寫正在運行的jar文件

ProcessBuilder builder = new ProcessBuilder(
      "cmd.exe", 
      "/c", 
      "timeout 10", 
      "&&", 
      "move", 
      "/Y", 
      file.toAbsolutePath().toString(), 
      System.getProperty("user.dir") 
); 

運行命令行,睡眠10秒並移動下載文件。當命令行正在休眠時,我關閉程序。但是,當我使用「& &」它不起作用,但是當我使用「&」它工作,但不睡覺。

回答

0

什麼想是這樣的:

File fileDestination = new File(System.getProperty("user.dir") + "\\" + file.getName()); 
file.renameTo(fileDestination); 

是,如果你避免使用OS相關的命令更容易。

sfc