kylar
asked on
File misbehaving with Unicode Surrogate Pairs
I have two scenarios:
#1) I can create a file using a different program (not java) and java is unable to read this file
#2) Java can't create a file using a unicode surrogate pair.
I've tried this on solaris and Macosx, using HFS and NFS, both local and over TCP.
this was saved properly in UTF-8 and was executed using -Dfile.encoding="UTF-8"
See the file below, in one I use the actual char, in the other I use the encoded version (both should work out to the same UTF8 String).
Why can't java open or create this file? What am I doing wrong? I *know* the filesystem can deal with the file, since I can create it using a different mechanism.
#1) I can create a file using a different program (not java) and java is unable to read this file
#2) Java can't create a file using a unicode surrogate pair.
I've tried this on solaris and Macosx, using HFS and NFS, both local and over TCP.
this was saved properly in UTF-8 and was executed using -Dfile.encoding="UTF-8"
See the file below, in one I use the actual char, in the other I use the encoded version (both should work out to the same UTF8 String).
Why can't java open or create this file? What am I doing wrong? I *know* the filesystem can deal with the file, since I can create it using a different mechanism.
public class FreakinUTF8{
public static void main(String args[]){
String tmp = "/tmp/\uD85C\uDD0D.txt";
//String tmp = "/tmp/\
.txt";//this is the encoded char.
File newFile = new File(tmp);
boolean b = false;
try {
b = newFile.createNewFile();
System.out.println("Created:"+b+" and exists:"+newFile.exists());
} catch (IOException e) {
e.printStackTrace();
}
}
}
Unfortunately the character doesn't work on this site, but i can tell you it's there
ASKER
What kind of box are you running it on? What kind of storage?
what version of java are you using? Have you tried latest?
it used to be a problem but was fixed ages ago
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4845710
what result exactly are you getting?
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4845710
what result exactly are you getting?
ASKER
I've tried with 1.5 and 1.6 on Solaris & MacOSX. I get this result on:
MacOSX when using locally attached HFS storage
MacOSX when using remote NFS storage
Solaris when using remote NFS storage
but not Solaris using local NFS storage.
I get an IOException when I run it:
Exception in thread "main" java.io.IOException: No such file or directory
at java.io.UnixFileSystem.cre ateFileExc lusively(N ative Method)
at java.io.File.createNewFile (File.java :883)
at UTF8Test.<init>(UTF8Test.j ava:20)
at SymlinkTest.main(SymlinkTe st.java:3)
MacOSX when using locally attached HFS storage
MacOSX when using remote NFS storage
Solaris when using remote NFS storage
but not Solaris using local NFS storage.
I get an IOException when I run it:
Exception in thread "main" java.io.IOException: No such file or directory
at java.io.UnixFileSystem.cre
at java.io.File.createNewFile
at UTF8Test.<init>(UTF8Test.j
at SymlinkTest.main(SymlinkTe
Do you get the same errors *outside Java*
I'd suggest raising a bug with Sun
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry yes apple :)
Open in new window