Typical use of IO streams
1. Cache input Files
BufferedReader in=Newnew filereader (file name)); String s; StringBuilder SB=new StringBuilder (); while ((S=in.readline ()) =null) {sb.append (s+ "\ n");} In.close ();
A string SB is used to store the contents of a file.
2. Input from memory
Work with the contents of the files saved in the SB in the previous step to output the contents of the memory to the console.
StringReader in=New StringReader (SB); while ((int c=in.read ())!=-1) {System.out.print ((char) c); }
3. Formatted memory input
4, the basic file output
The FileWriter object can write data to a file. First, create a filewriter that is connected to the specified file. In fact, we usually wrap it in bufferedwriter to buffer the output. PrintWriter can format the output of the data for easy reading.
5. Storing and recovering data
If we use DataOutputStream output data, Java guarantees that we can use DataInputStream to read the data accurately.
6. Read and write random access files
Using Randomaccessfile, it is similar to combining DataInputStream and dataoutputstream (because they implement the same interface: Datainput and DataOutput). In addition, the use of seek () can be moved around the file, arbitrarily modify a value in the file.
7. Pipeline Flow
The values of PipedInputStream, PipedOutputStream, Pipedreader and PipedWriter are reflected in the understanding of multithreading. Because pipeline flows are used for communication between tasks.
Utility for file read and write
A common task is to read the file into memory modification and save it to external memory.
Reading notes--java IO