Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.out character encoding

I'm running my Java program from command-line (Windows 7). To simplify matters, I describe only the relevant part.

public static void main(String[] args) {
    System.out.println("Árpád");
}

My output is garbage. It is obviously a character-encoding problem, the Hungarian characters of Á and á are not showing up correctly. I've tried the following:

public static void main(String[] args) {
    PrintStream ps = new PrintStream(System.out, true, "UTF-8");
    ps.println("Árpád");
}

But my output is still garbage. How can I resolve this character-encoding issue with Windows 7 command-line? Thanks

like image 608
Lajos Arpad Avatar asked Dec 25 '12 12:12

Lajos Arpad


1 Answers

I got your code to work by finding the right encoding from the command line, and then either using the PrintStream version with that encoding, or by specifying it on the command line and just using System.out.println.

To find the encoding on the commandline, run chcp. Here's the output I got:

Active code page: 850

That corresponds to the Java charset name of "IBM850". So this then creates the right output on the command line:

java -Dfile.encoding=IBM850 Test
like image 137
Jon Skeet Avatar answered Nov 08 '22 03:11

Jon Skeet