printStream与printWriter

PrintStream是用来操作byte,不经过映射
PrintWriter是用来操作Unicode,映射到unicode上
故一般需要处理中文时用PrintWriter

*****************************************************

System.out.println("aa");


PrintWriter out = new PrintWriter(System.out);
out.println("aa");
out.flush();

*****************************************************

在dos里面看到aa,都是ascii码,源代码首先根据系统的编码,保存成java文件,JVM编译的时候,“aa”会被转码成为UTF格式,就是unicode text fomat;

在println执行后,操作系统的显示会再把UTF转换成本地的字符编码显示给你看

*****************************************************

1 BufferedReader std = new BufferedReader(new InputStreamReader(System.in))//用户回车之后就开始执行main()了
2 String input = stdIn.readLine();
3 
4 PrintWriter stdOut = new PrintWriter(System.out, true);//true的意思是当调用printWriter时会自动刷新缓冲区,并换行进行输出;unicode字符流编码,可以跨平台
5 stdOut.println(" ");//字节流编码
6 
7 PrintWriter stdErr = new PrintWriter(System.err, true);//与stdOut无用法上的区别,只是可读性更好 8 stdErr.println("Incorrect number format");
9 PrintWriter stdErr = new PrintWriter(System.err, true);//区别println();和print()+flush();
10 stdErr.print("Incorrect number format");
11 stdErr.flush();
原文地址:https://www.cnblogs.com/li7anStrugglePath/p/12727051.html