Javase Basic Review Strategy "eight"

Source: Internet
Author: User

Entering the eighth chapter, we begin to discuss Java IO preliminary. In a Java program, the input \ Output operation of the data is carried out in a "stream" mode, and J2SDK provides a variety of "stream" classes for obtaining different kinds of data, which are entered and output by standard methods in the program.

1. Classification of input and output streams:

Multiple stream types (classes or abstract classes) are defined in the Java.io package to implement input and output functions, which can be categorized from different angles:

Depending on the direction of the data flow can be divided into input, output stream

Divided into byte stream and character stream according to different units of processing data

According to the different functions can be divided into byte stream and processing flow

All of the flow types provided by J2SDK are in the package java.io and are inherited to four abstract stream types:

  

2. Node flow and processing flow:

node flow to read data (text, memory) from a specific data source (node)

The processing flow is connected to the existing stream (the node stream and the processing stream), through the processing of the data for the program through more powerful read and write functions.

3, InputStream and OutputStream:

Streams that inherit from InputStream are used to enter data into the program, and the data units are bytes;

Streams that inherit from OutputStream are used to output data to the program, and the data units are bytes.

Note: The inputs and outputs mentioned in this article are relative to the program.

4, InputStream Common methods:

int read (): reads a byte and returns as an integer if the return value is-1 indicates that the read is complete

int read (byte[] buffer): Reads a series of bytes and saves it to the buffer byte array, returning the value to the actual number of bytes read

int read (byte[] buffer, int offset, int length): Reads the length of bytes and saves it to the buffer byte array, starting from the offset position, and returning the value to the actual number of bytes read

void Close (): Close stream frees memory resource

Long Skip (long N): skips n bytes without reading, returning the number of bytes actually skipped.

5, outputstream commonly used methods;

void write (int b): writes one byte of data to the output stream that is the lower 8 bits of parameter B.

void Write (byte[] buffer): Writes an array of type byte to the output stream

void Write (byte[] buffer, int off, int len): Starts from the specified position (off) in an array of one byte type, and Len bytes is written to the output stream

void Close (): Close stream frees memory resource

void Flush (): Writes all cached data from the output stream to the destination

Write here first, come back in the evening and add, please look forward to it.

Javase Basic Review Strategy "eight"

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.