我需要打開一個目錄中打開一個文件夾(探索文件夾)使用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
Ubantu無法通過「/」字符讀取路徑。您可以使用File.seperator在所有環境中工作。 –
不,它使用「/」字符。 – user3768048
您能否澄清一下:您已將'path'設置爲「/ home/hp/Documents」,但錯誤與「/ home/hp/Downloads ...」有關。你可以提供*全部*的相關代碼......不只是幾行。 – Dancrumb