title: Encoding issue on filename with Java 7 on OSX with jnlp/webstart
body: <p>I have this problem that has been dropped on me, and have been a couple of days of unsuccessful searches and workaround attempts. </p>
  
  <p>I have now an internal java swing program distributed by jnlp/webstart, on osx and windows computers, that, among other things, downloads some files from WebDav. </p>
  
  <p>Recently, on a test machine with OSX 10.8 and Java 7, filenames and directory names with accented characters started having those replaced by question marks. </p>
  
  <p>No problem on OSX with versions of Java before 7.</p>
  
  <p>example :</p>
  
  <p>XXXYYY_è_ABCD/</p>
  
  <p>becomes</p>
  
  <p>XXXYYY_?_ABCD/</p>
  
  <p>using <strong>java.text.Normalizer</strong> (NFD, NFC, NFKD, NFKC) on the original string, the result is different but still wrong : </p>
  
  <p>XXXYYY_e?_ABCD/</p>
  
  <p>or </p>
  
  <p>XXXYYY_e_ABCD/</p>
  
  <p>I know, from correspondence between [andrew.brygin at oracle.com] and [mik3hall at gmail.com] that </p>
  
  <blockquote>
    <p>Yes, file.encoding is set based on the locale that the jvm is running 
    on, and if you run your java vm in xxxx.UTF-8 locale, the
    file.encoding should be UTF-8, set to MacRoman  will be problematic.
    So I believe Oracle/OpenJDK7 behaves correctly. That said, as Andrew 
    Thompson pointed out, if all previous Apple JDK releases use MacRoman
    as the file.encoding for  english/UTF-8 locale, there is a
    "compatibility" concern here, it might worth putting  something in the
    release note to give Oracle/OpenJDK MacOS user a heads up.</p>
  </blockquote>
  
  <p><a href="http://mail.openjdk.java.net/pipermail/macosx-port-dev/2012-May/004290.html" rel="nofollow noreferrer">original mail</a></p>
  
  <p>from <strong><a href="https://stackoverflow.com/users/318758/joni?tab=summary">Joni Salonen</a></strong> blog (<a href="http://jonisalonen.com/2012/java-and-file-names-with-invalid-characters/" rel="nofollow noreferrer">java-and-file-names-with-invalid-characters</a>) i know that : </p>
  
  <blockquote>
    <p>You probably know that Java uses a “default character encoding” to
    convert binary data to Strings. To read or write text using another
    encoding you can use an InputStreamReader or OutputStreamWriter. But
    for data-to-text conversions deep in the API you have no choice but to
    change the default encoding.</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>What about file.encoding?</p>
    
    <p>The file.encoding system property can also be used to set the default
    character encoding that Java uses for I/O. Unfortunately it seems to
    have no effect on how file names are decoded into Strings.</p>
  </blockquote>
  
  <p>executing locale from inside the jnlp invariabily prints </p>
  
  <pre><code>LANG=
  LC_COLLATE="C"
  LC_CTYPE="C"
  LC_MESSAGES="C"
  LC_MONETARY="C"
  LC_NUMERIC="C"
  LC_TIME="C"
  LC_ALL=
  </code></pre>
  
  <p>the most similar problem on stackoverflow with a solution is this : 
  <a href="https://stackoverflow.com/questions/12987252/file-list-retrieves-file-names-with-non-ascii-characters-incorrectly-on-mac-os">encoding-issues-on-java-7-file-names-in-os-x</a></p>
  
  <p>but the solution is wrapping the execution of the java program in a script with</p>
  
  <pre><code>#!/bin/bash
  export LC_CTYPE="UTF-8" # Try other options if this doesn't work
  exec java your.program.Here
  </code></pre>
  
  <p>but I don't think this option is available to me because of the webstart, and I haven't found any way to set the LC_CTYPE environment variable from within the program.</p>
  
  <p>Any solutions or workarounds?</p>
  
  <p><strong>P.S. :</strong></p>
  
  <p>If we run the program directly from shell, it writes the file/directory correctly even on OSX 10+Java 7. 
  The problem appears only with the combination of JNLP+OSX+Java7</p>