问题
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