Java I/O streams; what are the differences?

后端 未结 9 1269
死守一世寂寞
死守一世寂寞 2020-12-12 18:44

java.io has many different I/O streams, (FileInputStream, FileOutputStream, FileReader, FileWriter, BufferedStreams... etc.) and I am confused in determining th

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-12 19:08

    Java input and output is defined in terms of an abstract concept called a “stream”, which is a sequence of data. There are 2 kinds of streams.

    • Byte streams (8 bit bytes) Æ Abstract classes are: InputStream and OutputStream
    • Character streams (16 bit UNICODE) Æ Abstract classes are: Reader and Writer

    java.io.* classes use the decorator design pattern. The decorator design pattern attaches responsibilities to objects at runtime. Decorators are more flexible than inheritance because the inheritance attaches responsibility to classes at compile time. The java.io.* classes use the decorator pattern to construct different combinations of behavior at runtime based on some basic classes.

    from the book Java/J2EE Job Interview Companion By K.Arulkumaran & A.Sivayini

提交回复
热议问题