路径不存在

时间:2014-06-13 13:12:44

标签: java file exception path

我决定测试Java提供的文件创建可能性:

我尝试制作一个在系统桌面上创建文件的程序。

要获取位置,我执行了以下操作:

String targetLoc = System.getProperties("user.home") + "/Desktop"; //Returns /Users/targetUser/Desktop

然后创建文件:

File file = new File(targetLoc + "/testfile.txt"); //I'm aware of the slash before the name :)

try{

file.createNewFile();

}catch(Exception exception){

exception.printStackTrace();

}

即使我没有看到上述任何错误,我也会得到InvalidPathException

为什么我会收到错误?

StackTrace On Request:

java.io.IOException: No such file or directory
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:883)
at com.Code0.FileCreater.Main.MainFF.main(MainFF.java:41)

答案:

这是一个简单的搞砸,我将错误的值分配给主变量。

1 个答案:

答案 0 :(得分:0)

这是一个简单的搞砸,我将错误的值分配给主变量。

非常感谢大家的支持。

此致

编码0

相关问题