io study notes

I. byte stream

            1.OutputStream

          This abstract class is a superclass of all classes of the output byte stream. Receiving the output byte output stream of bytes and sent to a receiver unit

              2.FileOutputStream

          OutputStream there are many subclasses, which subclasses FileOutputStream used to write data to a file. FileOutputStream class, i.e., file output stream for writing data to Filethe output stream.

             Construction method:

           

           Writing a file and line:

                We direct new new FileOutputStream (File) This creates an object, data is written, it will overwrite the original file, then we want to continue to write the contents of the original file, how to do it? Continue to have access FileOutputStream the API. Found in the constructor FileOutputStream, it is possible to accept a boolean value, if the value is true, it will continue to add the file last.

            Construction method 

           Three kinds of writing the same manner as the parent

3. The input stream of bytes InputStream

int read (): read a byte and returns, no byte -1.

int read (byte []): the number of bytes to read a certain amount, and stores the byte array and returns the read byte

method:

 

4.FileInputStream class

               Construction method

               The method is substantially the same parent class

Two. Jifuryu

1. The character input stream Reader

Summary:

  1. read (): read and return a single character
  2. read (char []): the read data to the array, and returns the number of the read.

2. FileReader class

                   Construction method:

                 用的比较多的是来自父类的两个方法

                      read():读取单个字符并返回

                      read(char[]):将数据读取到数组中,并返回读取的个数。

 4.字符输出流Writer

既然有专门用于读取字符的流对象,那么肯定也有写的字符流对象,查阅API,发现有一个Writer类,Writer是写入字符流的抽象类。其中描述了相应的写的动作。

 5.FileWrite类

6.flush()和close()的区别? 

           flush():将流中的缓冲区缓冲的数据刷新到目的地中,刷新后,流还可以继续使用。

           close():关闭资源,但在关闭前会将缓冲区中的数据先刷新到目的地,否则丢失数据,然后在关闭流。流不可以使用。如果写入数据多,一定要一边写一边刷新,最后一次可以不刷新,由close完成刷新并关闭。

 

Guess you like

Origin blog.csdn.net/qq_36897901/article/details/81271647