yea*_* me 2 java encoding utf-8
当我写一些西里尔文本,System.out.println("Русскийязык") - 然后它推出这个╨єёёъшщч√ъ,使用Windows控制台,怎么可以这个修复?,文件编码是utf-8,但它没关系,当它是ansii或windows-1251时,输出相同.
import java.io.PrintStream;
class Kyrill {
public static void main(String args[])
throws java.io.UnsupportedEncodingException
{
String ru = "??????? ????";
PrintStream ps = new PrintStream(System.out, true, "UTF-8");
System.out.println(ru.length());
System.out.println(ru);
ps.println(ru);
}
}
D:\Temp :: chcp 65001
Aktive Codepage: 65001.
D:\Temp :: javac -encoding utf-8 Kyrill.java && java Kyrill
12
??????? ????
??????? ????? ????
Run Code Online (Sandbox Code Playgroud)
请注意,您可能会在输出中看到一些尾随垃圾(我这样做),但如果您将输出重定向到文件,您会发现这只是一个显示器.
因此,您可以使用PrintStream使其工作.该System.out中使用该平台的编码(CP1252对我来说),而且没有西里尔字母.
另外需要注意编码业务:
D:\Temp :: chcp 1251
Aktive Codepage: 1251.
:: This is another codepage (8 bits only) that maps bytes to cyrillic characters.
:: Edit the source file to have:
:: PrintStream ps = new PrintStream(System.out, true, "Windows-1251");
:: We intend to match the console output; else we won't get the expected result.
D:\Temp :: javac -encoding utf-8 Kyrill.java && java Kyrill
12
??????? ????
??????? ????
Run Code Online (Sandbox Code Playgroud)
所以,你可以看到,相反,有些人认为,在Windows控制台不神交的Unicode的休闲感,它可以打印希腊和俄罗斯.