I'm dealing with code that does various IO operations with files, and I want to make it able to deal with international filenames. I'm working on a Mac with Java 1.5, and if a filename contains Unicode characters that require surrogates, the JVM can't seem to locate the file. For example, my test file is:
"草鷗外.gif"
which gets broken into the Java characters \u8349\uD85B\uDFF6\u9DD7\u5916.gif
If I create a file from this filename, I can't open it because I get a FileNotFound exception. Even using this on the folder containing the file will fail:
File[] files = folder.listFiles();
for (File file : files) {
if (!file.exists()) {
System.out.println("Failed to find File"); //Fails on the surrogate filename
}
}
Most of the code I am actually dealing with are of the form:
FileInputStream instream = new FileInputStream(new File("草鷗外.gif"));
// operations follow
Is there some way I can address this problem, either escaping the filenames or opening files differently?