Current position:  Home > Default > UTF-16 and file names

UTF-16 and file names

Time:October 11
Advertisement
Hi,
On Windows (2K & XP atleast) you can have file names containing characters that are represented using UTF-16. E.g. The unicode character \ubf3f (decimal equivalent 48959). Below is a snippet of code that attempts to create a file containing this character.
File f = new File ("c:/temp", "\ubf3f.txt");
FileWriter w = new FileWriter(f);
w.write("a");
w.close();
And the result is the following:
java.io.FileNotFoundException: d:\temp\?.txt (The filename, directory name, or volume label syntax is incorrect)
     at java.io.FileOutputStream.open(Native Method)
     at java.io.FileOutputStream.<init>(FileOutputStream.java:97)
     at java.io.FileOutputStream.<init>(FileOutputStream.java:57)
     at java.io.FileOutputStream.<init>(FileOutputStream.java:127)
     at java.io.FileWriter.<init>(FileWriter.java:58)
Clearly java is unable to interpret the file name. So I created the file on windows directly and it was fine. Then I tried to do a file.exists() test and it returned false. So either ways, I'm unable to work with this file in java.
Appreciate if some one can throw some light on why this is happening and what needs to be done to solve it.
Pradeep
Advertisement
Forgot to mention that the java version is 1.3.1_03-b03. Before posting I searched the bug database but couldn't find something that was related. If some one finds it, please do post the bug number.
Thanks,
Pradeep