title: Encoding of file names in Java
body: <p>I am running a small Java application on an embedded Linux platform. After replacing the Java VM JamVM with OpenJDK, file names with special characters are not stored correctly. Special characters like umlauts are replaced by question marks.</p>
  
  <p>Here is my test code:</p>
  
  <pre><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 &amp; 255) + " ");
                  }
                  System.out.println();
  
                  try {
                          File f = new File(name);
                          f.createNewFile();
                  } catch (IOException e) {
                          e.printStackTrace();
                  }
          }
  
  }
  </code></pre>
  
  <p>Running it gives the following output:</p>
  
  <pre><code>name = umlaute-???
  name in Bytes: 75 6d 6c 61 75 74 65 2d 3f 3f 3f
  </code></pre>
  
  <p>and file called umlaute-??? is created.</p>
  
  <p>Setting the properties file.encoding and sun.jnu.encoding to UTF-8 gives the correct strings in the terminal, but the created file is still umlaute-???</p>
  
  <p>Running the VM with strace, I can see the system call</p>
  
  <pre><code>open("umlaute-???", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0666) = 4
  </code></pre>
  
  <p>This shows, that the problem is not a file system issue, but one of the VM.</p>
  
  <p>How can the encoding of the file name be set?</p>