2013-12-24 31 views
0

我有這樣的代碼:如何調用相對於當前目錄的代碼。

String[] cmd = { "osascript","mylocation" }; 
Process process = Runtime.getRuntime().exec(cmd); 
process.waitFor(); 

位置myLocation文件是我script文件夾內。此課程在src文件夾中。我試過../script/file,這是行不通的。

如何在script文件夾中調用該文件?

+0

你在找這個? http://stackoverflow.com/questions/4871051/getting-the-current-working-directory-in-java – Kon

回答

0

從Javadoc文檔Runtime

public Process exec(String[] cmdarray, 
      String[] envp, 
      File dir) 
      throws IOException 

執行指定環境和工作目錄的獨立進程中指定的命令和參數。

0

你需要做的提供相對路徑下面給出:

String[] cmd = { "..\\script\\osascript", "mylocation" }; 
    Process process = Runtime.getRuntime().exec(cmd); 
    process.waitFor();