Basic principles for Java I/O usage

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.