Extended Ascii doesn't work in console!

user328898 picture user328898 · Feb 24, 2011 · Viewed 7.5k times · Source

For example System.out.println("╚"); displays as a ?, same goes for System.out.println("\u255a");

Why doesn't this work? Stdout does indeed support these characters so I don't get it.

Answer

Josh Lee picture Josh Lee · Feb 24, 2011

See this question. When Java’s default character encoding is not UTF-8 — as is the case, it seems, on Windows and OS X, but not Linux — then characters which fail to encode are converted to question marks. You can pass the correct switch (-Dfile.encoding=UTF-8 on some terminals, but I don’t have a Windows box in front of me) to the JVM’s command line, or you can set an environment variable. Portably determining what this should be might be impossible, but if you know that you will always run on the Win32 console, for example, you can choose a Charset to explicitly encode the characters before writing them to standard output, or you can directly write the bytes you need.