2014-06-23 30 views
0

我需要打開一個目錄中打開一個文件夾(探索文件夾)使用Java程序

String path="/home/hp/Documents"; 

我試圖打開通過這個目錄,

Desktop.getDesktop().open(new File(path)); 

這窗戶,但在Ubuntu中正常工作它說

java.io.IOException: Failed to show URI:file:/home/hp/Downloads/drawable/ 

當我使用,

Runtime runTime = Runtime.getRuntime(); 
Process process = runTime.exec(path); 

它說,

Cannot run program "/home/hp/Downloads": java.io.IOException: error=13, Permission denied 
+2

Ubantu無法通過「/」字符讀取路徑。您可以使用File.seperator在所有環境中工作。 –

+0

不,它使用「/」字符。 – user3768048

+2

您能否澄清一下:您已將'path'設置爲「/ home/hp/Documents」,但錯誤與「/ home/hp/Downloads ...」有關。你可以提供*全部*的相關代碼......不只是幾行。 – Dancrumb

回答

0

像神山野牛在評論中說,在地方/使用File.separator應該讓跨平臺工作。

+0

path =「/ home/hp/Downloads」所以我該如何使用文件分隔符 – user3768048

+0

'path = File.separator +「home」+ File.separator +「hp」+ File.separator +「Downloads」' –

+0

它仍然沒有'它說,無法運行程序「/ home/hp/Downloads」:java.io.IOException:error = 13,Permission denied \t at java.lang.ProcessBuilder.start(ProcessBuilder.java:488) \t at java.lang.Runtime.exec(Runtime.java:612) \t at java.lang.Runtime.exec(Runtime.java:450) \t at java.lang.Runtime.exec(Runtime.java:347) – user3768048