我已經寫了一個腳本在java中使用我正在執行.exe文件來安裝應用程序之後,我複製通過安裝生成的文件到遠程位置。但問題是在安裝完成之前,下一步將文件複製到機器位置正在發生。因此導致粘貼空文件,因爲安裝沒有完成,因此文件存在。我如何才能停止我的過程,直到前一步驟結束。我試圖使用thread.sleep(10000),但這並不是幫助,因爲安裝時間可能會有所不同。我怎樣才能停止我的過程,直到前面的步驟結束
public class threadJoin {
public static void main(String s[]){
Runnable r = new Runnable() {
@Override
public void run() {
File f = new File("C:\\D\\EVProject\\");
FilenameFilter textFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith("EVProject");
}
};
File[] files = f.listFiles(textFilter);
for (File file : files) {
try {
String filexy = file.getCanonicalPath();
System.out.print(filexy);
Runtime.getRuntime().exec(filexy);
//Thread.sleep(10000);
} catch (IOException ex) {
Logger.getLogger(threadJoin.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
String l ="C:\\Program Files\\PD ";
String m = "C:\\0.0.9.8";
File srcDir = new File(l);
File destDir = new File(m);
try {
FileUtils.copyDirectory(srcDir, destDir);
} catch (IOException e) {
}
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
};
Thread t1= new Thread(r);
Thread t2 = new Thread(r2);
t1.start();
try{
t1.join();
}catch(InterruptedException e){
}
t2.start();
}
}
你能顯示代碼嗎? –
您的程序如何知道安裝完成? –
它不檢查安裝是否完成。我的程序只是調用.exe文件@DanielWiddis – BleedCode