问题
It seems that the following file.listFiles() is broken on OpenJDK 7 on OS X.
This code snippet will print "This file has a euro symbol...does't exist".
final String pathname = System.getProperty("user.home") +
"/folderThatContainsAFileWithTheEuroSymbol/";
final File folder = new File(pathname);
for (File file : folder.listFiles()) {
if (!file.exists()) {
System.out.println("This file has a euro symbol in its name, it exists and yet file.exists says it doesn't exist");
}
}
It seems to be a known problem.
I'm looking for a work-around. This is for consumer software, so ideally the solution would involve no low-level chicanery on the part of the end user. I'm hoping there is a solution which solely involves a small code change on my behalf.
There is a suggested solution here, but that involves setting a command line environment variable, which is beyond the realm of many of my users.
Any ideas?
回答1:
This is fixed in the Java Development Kit 7 Update 10 (JDK 7u10).
来源:https://stackoverflow.com/questions/13762173/file-listfiles-on-openjdk7-os-x-broken-on-file-names-that-contain-a-euro-symbo