是否更好地通过Console对象打印 - 它处理"特殊字符"更好?

时间:2014-07-08 18:06:53

标签: java character-encoding console character command-prompt

在我的书中,我读到以下内容:

import java.io.Console;
// better to print thro' Console object - it handles "special characters" better
class SpecialCharHandling {
    public static void main(String []args) {
    // string has three Scandinavian characters
        String scandString = "å, ä, and ö";
    // try printing scandinavian characters directly with println
        System.out.println("Printing scands directly with println: " + scandString);
    // now, get the Console object and print scand characters thro' that
        Console console = System.console();
        console.printf("Printing scands thro' console's printf method: " + scandString);
    }
}
  

此程序打印的内容:直接用

打印scands
Printing scands directly with println: •, •, and ÷ 

Printing scands thro' console's printf method: å, ä, and ö 
  

从这个输出可以看出,Console的printf()方法(以及其他方法)   方法)对特殊字符有更好的支持。

我尝试在本地启动此应用程序。我得到了不同的结果:

Printing scands directly with println: ├е, ├д, and ├╢
Printing scands thro' console's printf method: Г?, Г¤, and Г?

如何解释与书的区别?

0 个答案:

没有答案