I know it's technically a bug to append whitespace around file names, but I'd just like to know why the following code returns true on Windows, but false on Linux:
public static void main(String[] args) {
File file = new File("some_file_that_exists "); // note the whitespace at the end
System.out.println(file.exists());
}
I'm using Windows 7 64-bit with jdk1.6.0_31, and retried on Linux 2.6.18 with jdk1.6.0_06. Note that the file does not have a space at the end of its name.
This should be because windows does not allow space at end, and when java calls OS, OS removes/does not consider space at end.
Whereas, linux allows space at end, so it does exact check and tries to find file with spaces at end of file name.
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