<p>We try to use Java and UTF-8 on Windows. The application writes logs on the console, and we would like to use UTF-8 for the logs as our application has internationalized logs.</p>

<p>It is possible to configure the JVM so it generates UTF-8, using <code>-Dfile.encoding=UTF-8</code> as arguments to the JVM. It works fine, but the output on a Windows console is garbled.</p>

<p>Then, we can set the code page of the console to 65001 (<code>chcp 65001</code>), but in this case, the <code>.bat</code> files do not work. This means that when we try to launch our application through our script (named start.bat), absolutely nothing happens. The command simple returns:</p>

<pre><code>C:\Application&gt; chcp 65001
Activated code page: 65001
C:\Application&gt; start.bat

C:\Application&gt;
</code></pre>

<p>But without <code>chcp 65001</code>, there is no problem, and the application can be launched.</p>

<p>Any hints about that?</p>

[{'answer_id': 55262, 'author': 'sblundy', 'author_id': 4893, 'author_profile': 'https://Stackoverflow.com/users/4893', 'pm_score': -1, 'selected': False, 'text': '<p>Have you tried <a href="http://en.wikipedia.org/wiki/PowerShell" rel="nofollow noreferrer">PowerShell</a> rather than old cmd.exe.</p>\n'}, {'answer_id': 55307, 'author': 'erickson', 'author_id': 3474, 'author_profile': 'https://Stackoverflow.com/users/3474', 'pm_score': 4, 'selected': True, 'text': '<p>Try <code>chcp 65001 &amp;&amp; start.bat</code></p>\n<p>The <code>chcp</code> command changes the code page, and 65001 is the Win32 code page identifier for UTF-8 under Windows 7 and up. A code page, or character encoding, specifies how to convert a Unicode code point to a sequence of bytes or back again.</p>\n'}, {'answer_id': 265734, 'author': 'Renato Soffiatto', 'author_id': 30477, 'author_profile': 'https://Stackoverflow.com/users/30477', 'pm_score': 0, 'selected': False, 'text': '<p>We had some similar problems in Linux. Our code was in ISO-8859-1 (mostly cp-1252 compatible) but the console was UTF-8, making the code to not compile. Simply changing the console to ISO-8859-1 would make the build script, in UTF-8, to break. We found a couple of choices:<br>\n1- define some standard encoding and sticky to it. That was our choice. We choose to keep all in ISO-8859-1, modifying the build scripts.<br>\n2- Setting the encoding before starting any task, even inside the build scripts. Some code like the erickson said. In Linux was like :</p>\n\n<pre><code>lang=pt_BR.ISO-8859-1 /usr/local/xxxx\n</code></pre>\n\n<p>My eclipse is still like this. Both do work well.</p>\n'}, {'answer_id': 7610736, 'author': 'Roger F. Gay', 'author_id': 490484, 'author_profile': 'https://Stackoverflow.com/users/490484', 'pm_score': 0, 'selected': False, 'text': '<p>Windows doesn\'t support the 65001 code page: <a href="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/chcp.mspx?mfr=true" rel="nofollow">http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/chcp.mspx?mfr=true</a></p>\n'}, {'answer_id': 8921509, 'author': 'YIN SHAN', 'author_id': 1157731, 'author_profile': 'https://Stackoverflow.com/users/1157731', 'pm_score': 3, 'selected': False, 'text': '<p>Java on windows does NOT support unicode ouput by default. I have written a workaround method by calling Native API with JNA library.The method will call WriteConsoleW for unicode output on the console.</p>\n\n<pre><code>import com.sun.jna.Native;\nimport com.sun.jna.Pointer;\nimport com.sun.jna.ptr.IntByReference;\nimport com.sun.jna.win32.StdCallLibrary;\n\n/** For unicode output on windows platform\n * @author Sandy_Yin\n * \n */\npublic class Console {\n    private static Kernel32 INSTANCE = null;\n\n    public interface Kernel32 extends StdCallLibrary {\n        public Pointer GetStdHandle(int nStdHandle);\n\n        public boolean WriteConsoleW(Pointer hConsoleOutput, char[] lpBuffer,\n                int nNumberOfCharsToWrite,\n                IntByReference lpNumberOfCharsWritten, Pointer lpReserved);\n    }\n\n    static {\n        String os = System.getProperty("os.name").toLowerCase();\n        if (os.startsWith("win")) {\n            INSTANCE = (Kernel32) Native\n                    .loadLibrary("kernel32", Kernel32.class);\n        }\n    }\n\n    public static void println(String message) {\n        boolean successful = false;\n        if (INSTANCE != null) {\n            Pointer handle = INSTANCE.GetStdHandle(-11);\n            char[] buffer = message.toCharArray();\n            IntByReference lpNumberOfCharsWritten = new IntByReference();\n            successful = INSTANCE.WriteConsoleW(handle, buffer, buffer.length,\n                    lpNumberOfCharsWritten, null);\n            if(successful){\n                System.out.println();\n            }\n        }\n        if (!successful) {\n            System.out.println(message);\n        }\n    }\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/54952', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1430323/']