【发布时间】:2018-11-16 22:25:35
【问题描述】:
我正在编写一个通用函数来检查变量是否包含文件或目录。所以我想出了一个使用布尔返回类型函数来检查它的想法。像这样:
function boolean checkFileOrDirectory(File myFile){
// Assume file already exist
if(myFile.isDirectory()){
//myFile is a directory
return true;
} else {
//myFile is a file
return false;
}
}
我想知道这个函数的准确性。如果有人能告诉我是否有任何类型的文件类型不属于 isFile() 或 isDirectory() ,我将不胜感激?
【问题讨论】:
-
"Tests whether the file denoted by this abstract pathname is a **normal** file. A file is normal if it is not a directory and, in addition, satisfies other system-dependent criteria"。这来自isFile的文档。也许您只需要寻找文件不“正常”的那些例外情况 -
checkFileOrDirectory方法名称未准确描述其功能 -
如果不存在,they'll both return false.
-
file.exists() 怎么样; ?
-
我通过注释清楚地表明该文件存在。 @ErnestKiwele 我肯定会查看非“正常”文件,我应该从哪里开始?