I. Input and Output
1. Stream represents any data source capable of producing data or any receiving source capable of receiving data. In Java I/O, all streams (including input and out stream) have two types:
1.1 byte-oriented stream
A byte-oriented stream that reads or writes information to a stream in bytes. Byte-oriented streams include the following types:
1) input stream:
1) bytearrayinputstream: uses a buffer in the memory as an inputstream.
2) stringbufferinputstream: Use a String object as inputstream.
3) fileinputstream: uses a file as inputstream to read the file.
4) pipedinputstream: implements the pipe concept and is mainly used in the process.
5) sequenceinputstream: combines multiple inputstreams into one inputstream.
2) Out stream
1) bytearrayoutputstream: stores information in a buffer zone in the memory.
2) fileoutputstream: stores information in a file.
3) pipedoutputstream: implements the concept of pipe, which is mainly used in the process.
4) sequenceoutputstream: combines multiple outstreams into one outstream.
1.2 Unicode Character-oriented stream
A Unicode-oriented stream that reads or writes information from a stream in units of Unicode characters. Unicode-oriented streams include the following types:
1) input stream
1) chararrayreader: corresponds to bytearrayinputstream
2) stringreader: corresponds to stringbufferinputstream
3) filereader: corresponds to fileinputstream
4) pipedreader: corresponds to pipedinputstream.
2) Out stream
1) chararraywrite: corresponds to bytearrayoutputstream
2) stringwrite: no corresponding byte-oriented stream
3) filewrite: corresponds to fileoutputstream
4) pipedwrite: corresponds to pipedoutputstream
Character-oriented stream basically corresponds to a byte-oriented stream. The functions of the two corresponding classes are the same, and the words are different in operation. For example, chararrayreader and bytearrayinputstream both use a buffer in the memory as inputstream. The difference is that the former reads a byte of information from the memory each time, the latter reads one character from the memory each time.
1.3 conversions between two non-existing stream types
Inputstreamreader and outputstreamreader: convert a byte-oriented stream into a character-oriented stream.
2. Add attributes to stream
2.1 role of "adding attributes for stream"
Using the I/O APIs in Java described above, we can complete any operation we want to complete. However, through the sub-classes of filterinputstream and filteroutstream, we can add attributes for stream. The following is an example to illustrate the role of this function.
If we want to write data to a file, we can do this:
Fileoutstream FS = new fileoutstream(‑test.txt ");
Then, you can use write(writable writable) to write data to the test.txt file. However, if we want to implement the "First cache the data to be written into the file into the memory, then write the data in the cache into the file" function, none of the above APIs can meet our needs. However, we can use the sub-classes of filterinputstream and filteroutstream to add the required functions for fileoutstream.
2.2 various types of filterinputstream
2.2.1 encapsulate byte-oriented inputstream
1) datainputstream: reads data of basic types (such as int and char) from stream.
2) bufferedinputstream: Buffer
3) linenumberinputstream: records the number of rows in the input stream. You can call getlinenumber () and setlinenumber (INT)
4) pushbackinputstream: rarely used and generally used for Compiler Development
2.2.2 encapsulate character-oriented inputstream
1) there is no class corresponding to datainputstream. Unless you use bufferedreader when using Readline (), use datainputstream
2) bufferedreader: corresponds to bufferedinputstream
3) linenumberreader: corresponds to linenumberinputstream
4) pushbackreader: corresponds to pushbackinputstream
2.3 various types of filteroutstream
2.2.3 encapsulate byte-oriented outputstream
1) dataioutstream: outputs basic data types (such as int and char) to stream.
2) bufferedoutstream: Buffer
3) printstream: produce formatted output
2.2.4 character-oriented outputstream Encapsulation
1) bufferedwrite: corresponds
2) printwrite: corresponds
3. randomaccessfile
1) You can use the randomaccessfile object to read and write files.
2) when an object is generated, you can specify