First, according to the mode of operation

Reader- Character reads

  • The node flow
    • FileReader
    • PipedReader
    • CharArrayReader
  • Processing flow
    • BufferedReader 
    • InputStreamReader 

Writer- Write characters

  • The node flow
    • FileWriter
    • PipedWriter
    • CharArrayWriter
  • Processing flow
    • BufferedWriter 
    • OutputStreamWriter 
    • PrintWriter

InputStream- byte read

  • The node flow
    • FileInputStream
    • PipedInputStream
    • ByteArrayInputStream
  • Processing flow
    • BufferedInputStream 
    • DataInputStream 
    • ObjectInputStream 
    • SequenceInputStream

OutputStream- byte write

  • The node flow
    • FileOutputStream
    • PipedOutputStream
    • ByteArrayOutputStream
  • Processing flow
    • BufferedOutputStream 
    • DataOutputStream 
    • ObjectOutputStream
    • PrintStream

Node flow: Data can be read and written from or to a specific place (node). Processing flow: Is the connection and encapsulation of an existing stream, through the encapsulated stream function calls to achieve data read and write.

2. Classification by operation object

Buffering operation: BufferedReader BufferedWriter BufferedInputStream BufferedOutputStream Basic data type operation: DataInputStream DataOutputStream ObjectInputStream ObjectOutputStream conversion control: PrintWriter PrintStream file operation: InputStreamReader OutputStreamWriter FileReader FileWriter FileInputStream FileInputStream PipedReader PipedWriter PipedInputStream PipedOutputStream ByteArrayInputStream ByteArrayOutputStream CharArrayWriter CharArrayReader

The most common scenario encountered by individuals is file processing:

1. Copy the common file and copy the mesh to mesH2

File inputFile = new File("D:\\file\\mesh.txt");

File outFile = new File("D:\\file\\mesh2.txt");

FileInputStream fileInputStream = new FileInputStream(inputFile);

FileOutputStream fileOutputStream = new FileOutputStream(outFile);

byte[] bytes = new byte[1024]; // Bytes read each time

int len=0;

while((len=fileInputStream.read(bytes))! = -1){

    fileOutputStream.write(bytes,0,len);

}

fileOutputStream.close();

fileInputStream.close();
Copy the code

2. Buffer flow processing

File inputFile = new File("D:\\file\\mesh.txt");

File outFile = new File("D:\\file\\mesh2.txt");

FileInputStream fileInputStream = new FileInputStream(inputFile);

FileOutputStream fileOutputStream = new FileOutputStream(outFile);

BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);

BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);

byte[] bytes = new byte[1024]; // Bytes read each time

int len=0;

while((len=bufferedInputStream.read(bytes))! = -1){

    bufferedOutputStream.write(bytes,0,len);

}

bufferedOutputStream.close();

bufferedInputStream.close();

fileOutputStream.close();

fileInputStream.close();
Copy the code