Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用java程序打开文件夹_Java_File Permissions_Permission Denied - Fatal编程技术网

使用java程序打开文件夹

使用java程序打开文件夹,java,file-permissions,permission-denied,Java,File Permissions,Permission Denied,我需要打开一个目录浏览文件夹 String path="/home/hp/Documents"; 我试图通过这个打开一个目录 Desktop.getDesktop().open(new File(path)); 这在windows中运行良好,但在ubuntu中它说 java.io.IOException: Failed to show URI:file:/home/hp/Downloads/drawable/ 当我使用 Runtime runTime = Runtime.getRuntim

我需要打开一个目录浏览文件夹

String path="/home/hp/Documents";
我试图通过这个打开一个目录

Desktop.getDesktop().open(new File(path));
这在windows中运行良好,但在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

正如kailash gaur在评论中所说,使用File.separator代替/应该可以使其跨平台工作。

Ubantu无法通过/character读取路径。您可以使用File.separator在所有环境中工作。不,它使用/character。您能否澄清:您已将路径设置为/home/hp/Documents,但错误是关于/home/hp/Downloads。。。。你能提供所有相关的代码。。。不仅仅是几行。/home/hp/Downloads是一个文件夹,而不是一个可执行文件。因此,您无法通过运行时运行它。Runtimeexec需要一个可执行程序。谢谢。你能告诉我一种通过我的程序路径=/home/hp/Downloads打开文件夹的方法吗?那么我应该如何在这个路径中使用文件分隔符=file.separator+home+file.separator+hp+file.separator+Downloads仍然不起作用。它说,无法运行程序/home/hp/Downloads:java.io.IOException:error=13,在java.lang.ProcessBuilder.startProcessBuilder.java:488在java.lang.Runtime.execRuntime.java:612在java.lang.Runtime.execRuntime.java:450在java.lang.Runtime.execRuntime.java:347