java.io.IOException:系统找不到指定的路径 [英] java.io.IOException: The system cannot find the path specified

查看:3003
本文介绍了java.io.IOException:系统找不到指定的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打开我刚刚在我的代码中创建的文件(所以我确定该文件存在)

I am trying to open a file i just created in my code (so i am sure that the file exists)

代码如下:

File file = new File(filename);
file.createNewFile();
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
...
bw.close();

try {
    Desktop desktop = null;
    if (Desktop.isDesktopSupported()) {
        desktop = Desktop.getDesktop();
    }
    desktop.open(file);
} catch (Exception e) {
    ...
}



<但是,正如标题所示,我从desktop.open(文件)istruction获得了java.io.IOException:系统无法找到指定的路径。
问题肯定是文件路径名包含空格(转换为%20)。有没有办法避免这种情况?

But as the title says i get a "java.io.IOException: The system cannot find the path specified" from the desktop.open(file) istruction. The problem surely is that the file pathname contains spaces (which are translated into "%20"). Is there a way to avoid this?

推荐答案

我发现了真正的问题。
这不是我所想的%20。
我没有直接访问文件位置的权限。解释起来有点复杂...
我很抱歉我之前无法弄清楚真正的问题。

I found the real problem. It wasn't either the %20 as i supposed. I just hadn't the privileges to directly access the file location. It's a bit complicated to explain... i'm just sorry i coulnd't figure out the real problem before.

无论如何,谢谢你的建议!

Thanks for your suggestions anyway!

这篇关于java.io.IOException:系统找不到指定的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆