Print Arabic or other charset in System.out

时光怂恿深爱的人放手 提交于 2019-12-31 02:42:26

问题


I'm tyring to print a String with Arabic characters:

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

However, I see from the Eclipse log console that the Arabic characters as displayed as series of these kind of characters èååêÒÉ

What could be missing in my code?


回答1:


try this:

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



回答2:


Make sure the console you use to display the output is also encoded in ISO-8859-6. In Eclipse , you need to go to Run Configuration > Common to do this.



来源:https://stackoverflow.com/questions/16644247/print-arabic-or-other-charset-in-system-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!