The Java I / O input and output streams Overview

       Stream is an ordered sequence of data, according to the type of operation can be divided into two kinds of input and output streams, the class responsible for various input and output defined in the Java language are placed java.io package. Wherein all of the input streams classes are the InputStream abstract class (input stream of bytes) or abstract class Reader (character input stream) subclass; and all output streams are abstract classes OutStream (output byte stream) or abstract class Writer (character output stream) subclass.

A. Input stream

      1. InputStream class is an abstract class of an input stream of bytes, is the parent of all the bytes of the input stream, which is a hierarchical structure:

      

                                                                                                                      1 InputStream class hierarchy of FIG.

      All the class method will lead to an IOException error is encountered, a brief description of part of the method:

  • read () method: Reads the next byte of data from the input stream. Return 0 int ~ 255 byte value within the range. If the end of the stream has been reached because no byte is available, it returns -1.
  • read (byte [] b): a length of the byte read from the input stream, and returns the number of bytes in the form of an integer.
  • mark (int readlimit) Method: placing a marker at the current position of the input stream, readlimit This parameter tells the number of bytes in the input stream prior to the failure position allows reading of the marking.
  • reset () method: Returns a pointer to the input made by the current mark.
  • skip (long n) Method: n bytes to skip the input stream and returns the actual number of bytes skipped.
  • markSupported (): If the current stream supports mark () / reset () operation returns True.
  • close (): Close this input stream and releases any system resources associated with the stream.

      2. Reader class is abstract character-input stream, all character-input streams are its subclasses, its hierarchy as follows:

                                                                   

                                                                                                                      图2 Reader类的层次结构

        Reader类中方法与InputStream类中的方法类似。

二. 输出流

     1. OutputStream类是字节输出流的抽象类,此抽象类是表示输出字节流的所有类的超类,其层次结构为:

                                                                        

                                                                                                                      图3 OutputStream类的层次结构

      OutputStream类中的所有方法均返回void,在遇到错误时引发IOException异常,简单说明部分方法:

  • write(int b)方法:将指定的字节写入此输出流。
  • write(byte[] b)方法:将b个字节从指定的byte数组写入此输出流。
  • write(byte[] b, int off, int len)方法:将指定byte数组中从偏移量off开始的len个字节写入此输出流。
  • flush()方法:彻底完成输出并清空缓存区。
  • close()方法:关闭输出流。

       2. Write类是字符输出流的抽象类,所有的字符输出类都是它的子类,其层次结构为:

                                                               

                                                                                                         图4 Writer类的层次结构

 在学习过程中做做笔记。

 

Guess you like

Origin www.cnblogs.com/Shonve-xy/p/11236174.html