【发布时间】:2011-11-20 02:33:20
【问题描述】:
我正在尝试在文件系统上创建一个文件,但我不断收到此异常:
java.io.IOException: No such file or directory
我有一个现有目录,我正在尝试将文件写入该目录。
// I have also tried this below, but get same error
// new File(System.getProperty("user.home") + "/.foo/bar/" + fileName);
File f = new File(System.getProperty("user.home") + "/.foo/bar/", fileName);
if (f.exists() && !f.canWrite())
throw new IOException("Kan ikke skrive til filsystemet " + f.getAbsolutePath());
if (!f.isFile()) {
f.createNewFile(); // Exception here
} else {
f.setLastModified(System.currentTimeMillis());
}
获取异常:
java.io.IOException: No such file or directory
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:883)`
我对路径有写权限,但是没有创建文件。
【问题讨论】:
-
您能否在第一行之后添加到这一行,并显示输出:System.out.println(f);
-
您确定目录
.foo/bar确实存在? -
/.foo/bar 中的点是什么?
-
@denolk: unix 中的隐藏目录
标签: java file ioexception