isDirectory()对文件返回true [英] isDirectory() returns true for a file

查看:146
本文介绍了isDirectory()对文件返回true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的java程序中,我复制一个文件并删除新的文件。

在我的方法中 removeFile()我检查它是否是一个目录:

  String fileName =G:/1310628353186Examples.csv; 
文件f = new File(fileName);
if(f.isDirectory()){
System.out.println('+ fileName +是一个目录);
String [] files = f.list();
if(files!= null&& files.length> 0)
throw new IllegalArgumentException(Delete:directory not empty:+ fileName);
}

有时我得到'G:/ 1310628353186Examples。 csv'是一个目录,有时我不会。



当我调试代码和 f.isDirectory () true ,我查看 f.isDirectory 中的内容,调试器说这是 false



我在Windows 7 Professional上运行Eclipse SDK 3.4.0和JDK 1.6。 / p>

解决方案

这似乎是Windows引起的问题。 Linux没有这个问题。


In my java program I copy a file and delete the new file.

In my method removeFile() I check if it is a directory:

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);
}

Sometimes I get "'G:/1310628353186Examples.csv' is a directory", sometimes I don't.

When I debug the code and f.isDirectory() is true and I check what is in f.isDirectory, the debugger says that it's false.

I'm running Eclipse SDK 3.4.0 and JDK 1.6 on Windows 7 Professional.

解决方案

It seemed to be a problem caused by Windows. Linux does not have this problem.

这篇关于isDirectory()对文件返回true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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