title: Java - Japanese filenames garbled
body: <p>I am running a standalone java process which writes data to multiple xlsx files in a parent target directory and upon completion, the entire target directory is zipped and uploaded to cloud and a download link is provided to the user. The xlsx file names and the name of the zip file is user defined and not possible to change.</p>
  
  <p>The issue is with the names of the xlsx files created. If the filename selected by the user is Japanese, like </p>
  
  <blockquote>
    <p>サイン色紙プレゼントCPN_第2.xlsx</p>
  </blockquote>
  
  <p>the corresponding file that is created in the system is of the form:</p>
  
  <blockquote>
    <p>??????????CPN_?2?.xlsx</p>
  </blockquote>
  
  <p>The same files are being uploaded to cloud and user is seeing garbled file names. However, the Japanese name of the zip file is not garbled and is in Japanese only.</p>
  
  <p>Following is the code sample for creating xlsx files:</p>
  
  <pre><code>String fileName = userGivenName + "_" + randomUUID + ".xlsx";
  File file = new File(tmpParentDirectoryName, fileName);
  
  FileOutputStream outputStream = new FileOutputStream(file);
  workbook.write(outputStream);
  </code></pre>
  
  <p>In this case the absolute path of the xlsx file created is like : </p>
  
  <blockquote>
    <p>/tmpDirectoryPath/??????????CPN_?2?_0c6b37ee-97c4-44d4-b80d-dfe5eafe0045.xlsx</p>
  </blockquote>
  
  <p>Just like above there are multiple xlsx files created in the same <em>tmpDirectory</em></p>
  
  <p>Upon completion following is the code sample to create zip files and upload to cloud:</p>
  
  <pre><code>File[] files = getFilesInFolder(tmpDirectory);
  if (ArrayUtils.isEmpty(files)) {
          continue;
  }
  
  File zipFile = new File(targetDirectory, compressedFileName);
  createZipFile(files, zipFile);
  String url = uploadFile(compressedFileName, zipFile);
  </code></pre>
  
  <p>Following piece of code writes data to zip file:</p>
  
  <pre><code>public static void createZipFile(File[] files, File zipFile) {
      if (ArrayUtils.isEmpty(files)) {
          return;
      }
  
      byte[] buffer = new byte[1024];
      ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile));
  
      try {
          for (File file : files) {
              FileInputStream fis = new FileInputStream(file);
              try {
                  String fileName = URLDecoder.decode(file.getName(), "UTF-8");
                  ZipEntry zipEntry = new ZipEntry(fileName);
                  zos.putNextEntry(zipEntry);
                  int length;
                  while ((length = fis.read(buffer)) &gt; 0) {
                      zos.write(buffer, 0, length);
                  }
                  zos.closeEntry();
              } finally {
                  IOUtils.closeQuietly(fis);
              }
          }
      } finally {
          IOUtils.closeQuietly(zos);
      }
  }
  </code></pre>
  
  <p>The uploaded zip file has the correct Japanese name but the zip entries of the zip file have garbled xlsx filenames. </p>
  
  <p>The standalone java process has following encoding options:</p>
  
  <pre><code>-Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8
  </code></pre>
  
  <p>Following is the output of the locale command:</p>
  
  <pre><code>locale
  LANG=en_IN.UTF-8
  LC_CTYPE="en_IN.UTF-8"
  LC_NUMERIC="en_IN.UTF-8"
  LC_TIME="en_IN.UTF-8"
  LC_COLLATE="en_IN.UTF-8"
  LC_MONETARY="en_IN.UTF-8"
  LC_MESSAGES="en_IN.UTF-8"
  LC_PAPER="en_IN.UTF-8"
  LC_NAME="en_IN.UTF-8"
  LC_ADDRESS="en_IN.UTF-8"
  LC_TELEPHONE="en_IN.UTF-8"
  LC_MEASUREMENT="en_IN.UTF-8"
  LC_IDENTIFICATION="en_IN.UTF-8"
  LC_ALL=
  </code></pre>
  
  <p>Can someone direct me as to what am I doing wrong here ? I want the same filenames to be uploaded as given by the user.</p>