java – System. Out character encoding

I run my java program from the command line (Windows 7) To simplify matters, I will only describe the relevant parts

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

My output is garbage, which is obviously a character coding problem. The Hungarian characters of Á and á are not displayed 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 do I resolve this character encoding problem using the windows 7 command line? thank you

Solution

I find the correct encoding from the command line and use the version of printstream with that encoding, or by specifying it on the command line and using system out. Println to get your code

To find the encoding on the command line, run CHCP This is my output:

Active code page: 850

This corresponds to the Java character set name "ibm850" So the correct output is created on the command line:

java -Dfile.encoding=IBM850 Test
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>