[英]java isDirectory showing wrong result
I have the following code that checks if a file is a directory, and if not, creates it. 我有以下代码检查文件是否是目录,如果不是,则创建它。
File folder = new File(destFolder);
if (!folder.isDirectory()) {
if (!folder.mkdir()) {
System.out.println("Could not create " + folder.getAbsolutePath());
return null;
}
}
The code outputs "Could not create " always. 代码始终输出“无法创建”。 I checked and confirmed that the folder with that name already exists.
我检查并确认具有该名称的文件夹已存在。 What could be the reason?
可能是什么原因?
If I remove the destFolder, still it is showing the same error. 如果我删除destFolder,它仍然显示相同的错误。 Checked the permissions, I have read, write and execute permissions to the folder.
检查权限,我已经读取,写入和执行该文件夹的权限。 (Weird thing is, it was working till last Friday!)
(奇怪的是,它一直工作到上周五!)
My machine runs Windows 7, and I am running the code from Netbeans. 我的机器运行Windows 7,我正在运行Netbeans的代码。 Java Platform is - JDK 1.7
Java平台是 - JDK 1.7
You only get to the mkdir() call if the file is not a directory, in other words if it is a file. 如果文件不是目录,则只能访问mkdir(),换句话说,如果它是文件。 You're trying to run mkdir() against a file.
您正在尝试对文件运行mkdir()。 You should be checking to see if it exists, not if it's a directory.
您应该检查它是否存在,而不是它是否是目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.