macos – Java Mac create new File(path) – path with german umlauts

macos – Java Mac create new File(path) – path with german umlauts

You say you are trying to create a file, but your code lists the contents of a directory. Are you (unintentionally) listing the folder contents of a FILE? According to http://docs.oracle.com/javase/7/docs/api/java/io/File.html: If this abstract pathname does not denote a directory, then this method returns null.

So if, as I suspect, you are attempting to list the contents of a non-directory, your File[] array is null. Therefore, when you attempt to use it, your code will explode with an NPE

I dont know how Mac OS will treat umlauts in the file system. But if the directory could be handled correctly out of the JVM it has to work in it, too.

So try to list the name of the directory trough a listFiles() one level above:

File d = new File(/Volume/dir1/dir2/); 
for( File f : d.listFiles()) System.out.println(f.getName());

So you will see how the String has to look like for opening the file (also it really exists and is accessible from the VM);


SOLUTION:

File.listFiles() mangles unicode names with JDK 6 (Unicode Normalization issues)

macos – Java Mac create new File(path) – path with german umlauts

Leave a Reply

Your email address will not be published. Required fields are marked *