InputStreamReader和OutputStreamWriter都是转换流。InputStreamReader是将字节流转换为字符流,OutputStreamWriter是字符转字节流。那么BufferedWriter out =new BufferedWriter(new OutputStreamWriter(System.out))这句代码该怎么解释呢?BufferedWriter构造方法中是传一个Writer类型的字符流,可OutputStreamWriter却是将字符流转换为字节流的一个转换类型,怎么new OutputStreamWriter(System.out)就成了字符流了?还有就是System.out是PrintStream类型,而PrintStream有是OutputStream的子类,也就是说System.out本身就是字节流了,为甚么还要用new OutputStreamWriter将原本已是字节流的System.out转换为字节流呢?
摩诃迦叶
相关分类