File.isFile()返回不正确的结果? [英] File.isFile() returns incorrect result?
问题描述
public class Test {
public static void isFile() {
System.out.println(new File("D:\\a.log").isFile());
}
public static void main(String[] args) {
System.out.println(new File("D:\\a.log").isFile());
isFile();
}
}
预期结果是:
true
true
但实际上结果是:
false
true
文件D:\ a.log实际上存在并且路径正确,jdk版本是1.8.0_11,操作系统是win10
The file D:\a.log is actually exist and the path is correct, the jdk version is 1.8.0_11, and the os is win10
如何理解这一点?
推荐答案
main
方法中的字符串"D:\\a.log"
具有9个字符,isFile
方法中的字符串具有8个字符.
The string "D:\\a.log"
inside the main
method has 9 characters, the one in the isFile
method has 8 characters.
main
方法中的一个以不可见的Unicode字符U + 202A(从左向右嵌入")开头.
The one inside the main
method starts with invisible unicode character U+202A ("LEFT-TO-RIGHT EMBEDDING").
将main
中的字符串替换为isFile
中的字符串,或从main
中的字符串中删除第一个不可见的字符.
Replace the string inside main
with the string inside isFile
, or delete the first invisible character from the string in main
.
(注意:这表明复制粘贴您的实际代码的真正好处,因为问题出在您上面的问题中粘贴的代码中)
(Note: this shows the real benefit of copy-pasting your actual code, as the problem is in the code that you pasted in your question above)
这篇关于File.isFile()返回不正确的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!