我打算用阿拉伯字符打印一个字符串:
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); }