Error in file name encoding on OS X

This little java program fails when creating a new file with the Danish letter "? (U+00C5) and then trying to find the same file. It cannot find it - the name has been messed up in the encoding/decoding.

The program only fails on OS X 10.4. The charset is MacRoman. If I look for the file in OS X it looks fine.

It runs fine on Windows XP.

Anyone who can explain this?

publicclass Test

{

publicstaticvoid main(String []args)

{

try

{

String arr[] ={

"\u0026\u0416\u4E2D\u10346"//http://www.tbray.org/ongoing/When/200x/2003/04/26/UTF

,"\u00C5"//AA

,"\u00d8"//OE

,"\u00E6"//AE

};

for (int i = 0; i<arr.length; i++)

{

String filename = arr[i];

String folder ="/Users/.../shared/1/";

java.io.File f =new java.io.File(folder + filename);

f.createNewFile();

f =new java.io.File(folder);

boolean found =false;

String[] files = f.list();

for (int j=0; j><files.length; j++)

{

if (files[j].equals(filename))

found =true;

}

System.out.println(arr[i] +" : " + found);

}

}

catch (Exception ex)

{

System.out.println(""+ex);

}

}

>

[2478 byte] By [stigcAtSuna] at [2007-11-26 13:56:34]
# 1

Here is a even more clear example that something is wrong. CompareTo returns != 0 for all files in a folder, even when compared to the file object, from which a file was just created.

Again this works fine with Windows XP.

public class Test

{

public static void main(String []args)

{

try

{

String filename = "\u00C5"; //Danish ?/font>

String folderPath = "/Users/.../shared/";

//Create file.

java.io.File file = new java.io.File(folderPath + filename);

file.createNewFile();

//Loop folder

java.io.File folder = new java.io.File(folderPath);

java.io.File[] files = folder.listFiles();

for (int j=0; j<files.length; j++)

{

java.io.File folderFile = files[j];

System.out.println(folderFile + " compareTo: " + file.compareTo(folderFile));

}

}

catch (Exception ex)

{

System.out.println(""+ex);

}

}

}

Message was edited by:

stigcAtSun2>

stigcAtSun2a at 2007-7-8 1:36:09 > top of Java-index,Java Essentials,Java Programming...