title: Cannot use unicode filename as argument to Java program on Windows cmd, but wildcard works
body: <p>I tried to pass filename with unicode characters to my java program in Windows cmd, but the filename I got in program was broken. Those unicode characters were presented as <code>?</code>, and it threw IOException when I read those file.<br />
  However, if I use wildcard like <code>*.txt</code>, it works correctly.</p>
  <p>For example, I have a file called <code>[テスト]测试文件1.txt</code> in my directory.
  And I wrote a simple java program to show arguments it received, which also prints string bytes.</p>
  <pre class="lang-java prettyprint-override"><code>import java.util.Arrays;
  
  public class FileArg {
      public static void main(String[] args) {
          for (String fn: args) {
              System.out.println(fn);
              System.out.println(Arrays.toString(fn.getBytes()));
          }
      }
  }
  </code></pre>
  <p>My Java version is 15, and I have <code>chcp</code> to <code>65001</code>, also running program with <code>-Dfile.encoding=UTF-8</code> flag.<br />
  Then I run <code>java -Dfile.encoding=UTF-8 FileArg &quot;[テスト]测试文件1.txt&quot; [テスト]测试文件1.txt *.txt</code>.
  The filename is broken if I passed them directly, but it works perfectly with wildcard.</p>
  <p>The output:</p>
  <pre><code>[???]??文件1.txt
  [91, 63, 63, 63, 93, 63, 63, -26, -106, -121, -28, -69, -74, 49, 46, 116, 120, 116]
  [???]??文件1.txt
  [91, 63, 63, 63, 93, 63, 63, -26, -106, -121, -28, -69, -74, 49, 46, 116, 120, 116]
  [テスト]测试文件1.txt
  [91, -29, -125, -122, -29, -126, -71, -29, -125, -120, 93, -26, -75, -117, -24, -81, -107, -26, -106, -121, -28, -69, -74, 49, 46, 116, 120, 116]
  </code></pre>
  <p>Result:
  <a href="https://i.stack.imgur.com/GwDmT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GwDmT.png" alt="console output" /></a></p>
  <p>BTW, my default code page is <code>cp950</code> (BIG5).</p>
  <p>How could I get it work?</p>