I am running a small Java application on the embedded Linux platform. After replacing the Java VM JamVM with OpenJDK, file names with special characters are not saved correctly. Special characters, such as umlauts, are replaced by question marks.
Here is my test code:
import java.io.File; import java.io.IOException; public class FilenameEncoding { public static void main (String[] args) { String name = "umlaute-äöü"; System.out.println("\nname = " + name); System.out.print("name in Bytes: "); for (byte b : name.getBytes()) { System.out.print(Integer.toHexString(b & 255) + " "); } System.out.println(); try { File f = new File(name); f.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } }
The launch is as follows:
name = umlaute-??? name in Bytes: 75 6d 6c 61 75 74 65 2d 3f 3f 3f
and a file named umlaute - ???.
Setting the file.encoding and sun.jnu.encoding properties in UTF-8 gives the correct lines in the terminal, but the created file is still umlaute - ???
Starting a virtual machine using strace, I see a system call
open("umlaute-???", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0666) = 4
This shows that the problem is not a file system problem, but one of the virtual machines.
How can I set the encoding of a file name?
source share