General Usage principles of Java IO:
Principle 1: Data Sources (destinations:
1. File: (byte stream) fileinputstream, fileoutputstream;
(Character) filereader, filewriter
2. byte []: bytearrayinputstream, bytearrayoutputstream (byte stream)
3. Char []: chararrayreader, chararraywriter (character stream)
4. String: (byte stream) stringbufferinputstream, stringbufferouputstream
(Batch stream) stringreader, stringwriter
5. network data streams: (byte stream) inputstream, outputstream, (Bytes stream) reader, writer
Principle 2: whether to format the output score:
1. output to be formatted: printstream, printwriter
Principle 3: whether to buffer points:
1. Buffer: (byte stream) bufferedinputstream, bufferedoutputstream,
Bufferedreader, bufferedwriter
Principle 4: data format:
1. binary format (as long as it cannot be determined that it is plain text): inputstream, outputstream and all
Subclass of stream end
2. plain text format (including English letters, Chinese characters, and Other encoding methods): reader, writer, and all,
Subclass of writer
Principle 5. Input/Output score:
The input stream connects the pipe to the source, introduces the stream, and reads only.
The output stream connects the pipe to the source, and extracts the stream and exports it. It can only be written.
1. Input: reader, a subclass of the inputstream type
2. Output: a subclass of the writer and outputstream types.
Principle 6. Special needs:
1. Conversion class from stream to reader: inputstreamreader,
Outputstreamwriter
2. Object input and output: objectinputstream and objectoutputstream
3. inter-process communication: pipeinputstream, pipeoutputstream, pipereader, and pipewriter
4. Merge input: sequenceinputstream
5. Special requirements: pushbackinputstream, pushbackreader,
Linenumberinputstream, linenumberreader
General steps for using I/O
1. What is the most primitive data format? Principle 4
2. Whether input or output: Principle 5
3. Whether stream conversion is required: Principle 6: 1st points
4. What is the data source (destination)? Principle 1
5. buffer required or not: Principle 3 (Note: Do you need to pay attention to the definition of Readline ()? What is the ratio?
Read, write more special input or output methods)
6. Whether to format the output: Principle 2