我正在尝试打印带有阿拉伯字符的字符串:
private static void print(String msg, Object... args) {
try {
PrintStream ps = new PrintStream(System.out, true, "ISO-8859-6");
ps.println(String.format(msg, args));
} catch (UnsupportedEncodingException error) {
System.err.println(error);
System.exit(0);
}
}
但是,我从 Eclipse 日志控制台看到阿拉伯字符显示为一系列此类字符 èååêÒÉ
我的代码中可能缺少什么?
最佳答案
试试这个:
private static void print(String msg, Object... args) {
try {
PrintStream ps = new PrintStream(System.out, true, "UTF-8");
ps.println(String.format(msg, args));
} catch (UnsupportedEncodingException error) {
System.err.println(error);
System.exit(0);
}
}
public static void main (String[] args) throws UnsupportedEncodingException {
String arabicString = "كيف حالك";
print(arabicString);
}
关于java - 在 System.out 中打印阿拉伯语或其他字符集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16644247/