【发布时间】:2011-10-05 02:51:47
【问题描述】:
在我的 java 程序中,我复制了一个文件并删除了新文件。
在我的方法removeFile()我检查它是否是一个目录:
String fileName = "G:/1310628353186Examples.csv";
File f = new File(fileName);
if (f.isDirectory()) {
System.out.println( "'" + fileName + "' is a directory" );
String[] files = f.list();
if (files != null && files.length > 0)
throw new IllegalArgumentException("Delete: directory not empty: " + fileName);
}
有时我收到"'G:/1310628353186Examples.csv' is a directory",有时我没有。
当我调试代码并且 f.isDirectory() 是 true 并且我检查 f.isDirectory 中的内容时,调试器说它是 false。
我在 Windows 7 Professional 上运行 Eclipse SDK 3.4.0 和 JDK 1.6。
【问题讨论】:
-
什么是
fileName?使用System.out.println( "'" + f + "' is a directory" );检查f中的内容! -
你说
f.isDirectory()被评估为真,但调试器说它是假的?这不可能是真的;) -
我知道 :DI 启动调试器...它会跳转到 isDirectory() 的代码中...但是如果我用 watch 检查 isDirectory() 会显示错误...而 f.list( ) 为空。
-
也许值得尝试
isFile()而不是isDirectory() -
同样的问题...有时是真的...有时是假的。 isFile() 为 true 或 isDirectory()
标签: java file directory java-io