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();
}
}
The expected result is:
true
true
but actually the result is:
false
true
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
How to understand this??
The string "D:\\a.log"
inside the main
method has 9 characters, the one in the isFile
method has 8 characters.
The one inside the main
method starts with invisible unicode character U+202A ("LEFT-TO-RIGHT EMBEDDING").
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With