在System.out中打印阿拉伯语或其他字符集

我要打印一个带有阿拉伯字符的字符串:

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); } 

确保用于显示输出的控制台也以ISO-8859-6编码。 在Eclipse中,您需要转到Run Configuration> Common来执行此操作。