Java stream

   java stream:

  - A stream refers to a series of flowing characters, which is a channel for sending information in a first-in, first-out manner;

  - A stream is an abstract representation of an input device or an output device. You can input and write data to the stream, and you can also write data from the stream;

- the stream has a clear direction:
  input stream: you can only read data from the stream, but not write data to the stream; (put the data in the file Data is read into memory in a stream)
  output stream: only data can be written to the stream, but not read from the stream; (the data in the memory is written to the file in a stream) In
             principle, these The data can be in any serial data source;
 
  - In the java.io package, many input/output stream APIs are encapsulated. In a program, the objects of these input/output streams are called stream objects;
 
  - Stream objects are often constructed in connection with a data source (such as a file). The data source is divided into the source data source and the target data source;
  the input stream is related to the source data source;
  the output stream is related to the target data source;
 
  - the output stream of java mainly uses OutputStream and Writer as the base class, and the input stream is mainly composed of InputStream and Reader are used as base classes;
 
  - According to the unit of operation data, the stream can be divided into byte stream and character stream;
     the minimum data unit of byte stream operation is 8-bit bytes, and the minimum unit of character stream operation 16-bit characters. Byte streams are recommended for binary data, while character streams are used for text (Chinese). They are used exactly the same;

-------------------------------------------------- ------------------

  v byte stream
   input stream:
  InputStream if = new FileInputStream();

   output stream:
  OutputStream fo = new FileOutputStream();

v character stream
   input stream:
   Reader fr = new FileReader();

   Output Stream:
   Writer fw = new FileWriter();

v Character Buffered Stream
   Input Stream:
  BufferedReader br = new BufferedReader();

   Output Stream:
  BufferedWriter bw = new BufferedWriter();

  v Binary
   Input Stream:
   DataInputStream di = new DataInputStream();

  Output Stream:
   DataOutputStream do = new DataOutputStream();

v Serialization:
   Input Object:
  ObjectInputStream oi = new ObjectInput(new FileInputStream("E:/me.txt"));

   输出对象:
   ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("E:/me.txt"));

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326403068&siteId=291194637