Possible bugs with Java file system and non latin characters in file names

Martijn Verburg martijnverburg at gmail.com
Sun Oct 30 06:42:51 PDT 2011


Hi Alan,

<snip>

> This is the long standing with java.io.File using a String to represent a
> file name when the underlying platform or file system uses bytes
> (http://bugs.sun.com/view_bug.do?bug_id=4899439 has some background).

I thought that might be the case, thanks for looking that up!
Hopefully I'll get
access to that DB again soon :|, but I think I'll stop annoying Georges for the
day :-)

> You are usually work around this by changing your locale (possibly hu_HU
> for Hungarian in this case).

Right, I just tried that on Ubuntu and indeed that does the trick.

> Alternatively change the code to use the new
> API. For this code fragment then replace the listFiles and for loop with the
> following:
>
> try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir.toPath()))
> {
>     for (Path entry: stream) {
>         try (Reader reader = Files.newBufferedReader(entry,
> Charset.defaultCharset())) {
>         }
>     }
> }
>
> and it should do what you expect.

Yes, I've already advised the client to move to Java 7 for their File
I/O work - this issue will
hopefully help push them over the edge (good for everyone)!

Thanks again Alan, appreciate you looking into this.

Cheers,
Martijn


More information about the nio-dev mailing list