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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With