title: Java saving a file with special characters in file name
body: <p>I'm having a problem on Java file encoding.</p>
  
  <p>I have a Java program will save a input stream as a file with a given file name, the code snippet is like:</p>
  
  <pre><code>File out = new File(strFileName);
  Files.copy(inStream, out.toPath());
  </code></pre>
  
  <p>It works fine on Windows unless the file name contains some special characters like <code>Ö</code>, with these characters in the file name, the saved file will display a garbled file name on Windows.</p>
  
  <p>I understand that by applying JVM option <code>-Dfile.encoding=UTF-8</code> this issue can be fixed, but I would have a solution in my code rather than ask all my users to change their JVM options.</p>
  
  <p>While debugging the program I can see the file name string always shows the correct character, so I guess the problem is not about internal encoding.</p>
  
  <p>Could someone please explain what went wrong behind the scene? and is there a way to avoid this problem programmatically? I tried get the bytes from the string and change the encoding but it doesn't work.</p>
  
  <p>Thanks.</p>