-
reader结尾的类读出来的都是JAVA支持的char类型,也就是unicode字符, 而inputstream,outputstream类及其子类读出来的,或者是写出去的都是byte数组。
举例来说,BufferedReader有一个函数是readLine, 功能是读取一行数据,DataInputStream也有该函数,但一个读出来是char类型的字符串,一个读出来的是平台支持的类型。这两个类有一个共同的BUG,就是以/r/n来识别一行的结束,如果一行只是以/r结束,就会挂起,然而MAC机子是以/r来标识一行结尾的。下面这个类解决 了这个问题:
The InputStreamReader and OutputStreamWriter classes act as decorators on top of input and output streams that change the interface from a byte-oriented interface to a character-oriented interface. Once this is done, additional character-oriented filters can be layered on top of the reader or writer using the java.io.FilterReader and java.io.FilterWriterclasses. As with filter streams, there are a variety of subclasses that perform specific filtering, including:
-
BufferedReader
-
BufferedWriter
-
LineNumberReader
-
PushbackReader
-
PrintWriter
-