title: Add non-ASCII file names to zip in Java
body: <p>What is the best way to add <strong>non-ASCII</strong> file names to a <strong>zip file</strong> using <strong>Java</strong>, in such a way that the files can be properly read in both <strong>Windows</strong> and <strong>Linux?</strong></p>
  
  <p>Here is one attempt, adapted from <a href="https://truezip.dev.java.net/tutorial-6.html#Example" rel="noreferrer">https://truezip.dev.java.net/tutorial-6.html#Example</a>, which works in Windows Vista but fails in Ubuntu Hardy. In Hardy the file name is shown as abc-ЖДФ.txt in file-roller.</p>
  
  <pre><code>import java.io.IOException;
  import java.io.PrintStream;
  
  import de.schlichtherle.io.File;
  import de.schlichtherle.io.FileOutputStream;
  
  public class Main {
  
      public static void main(final String[] args) throws IOException {
  
          try {
              PrintStream ps = new PrintStream(new FileOutputStream(
                      "outer.zip/abc-åäö.txt"));
              try {
                  ps.println("The characters åäö works here though.");
              } finally {
                  ps.close();
              }
          } finally {
              File.umount();
          }
      }
  }
  </code></pre>
  
  <p>Unlike java.util.zip, truezip allows specifying zip file encoding. Here's another sample, this time explicitly specifiying the encoding. Neither IBM437, UTF-8 nor ISO-8859-1 works in Linux. IBM437 works in Windows.</p>
  
  <pre><code>import java.io.IOException;
  
  import de.schlichtherle.io.FileOutputStream;
  import de.schlichtherle.util.zip.ZipEntry;
  import de.schlichtherle.util.zip.ZipOutputStream;
  
  public class Main {
  
      public static void main(final String[] args) throws IOException {
  
          for (String encoding : new String[] { "IBM437", "UTF-8", "ISO-8859-1" }) {
              ZipOutputStream zipOutput = new ZipOutputStream(
                      new FileOutputStream(encoding + "-example.zip"), encoding);
              ZipEntry entry = new ZipEntry("abc-åäö.txt");
              zipOutput.putNextEntry(entry);
              zipOutput.closeEntry();
              zipOutput.close();
          }
      }
  }
  </code></pre>