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);
}
}
>

