file.listFiles() on OpenJDK7 OS X broken on file names that contain a euro symbol

你离开我真会死。 提交于 2019-12-23 20:32:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!