Java IO stream Analytics

Source: Internet
Author: User

Java IO streams are common in Java applications or Android applications, and use a very high frequency module. At that time each need to use this module is always a pen to forget the word feeling, do not know which stream to use or who should be used to package who.

So I took a moment to comb the structure of the block. One is to allow yourself to clarify the idea. Second, if there is still a pen to forget the word, read this article is good.

First, the Java IO Stream is divided into two major systems InputStream and reader, the former and its subclasses are mainly used to read the byte stream, the latter and its subclasses are mainly used to read the character stream. The following is the inheritance tree of the Inputsteram system

First, you can see the structure of the InputStream class, which defines several read methods, such as:

public abstract int Read ()
public int read (byte b[]) throws IOException
public int read (byte b[], int off, int len) throws IOException

The latter two methods give a concrete implementation, and the final call is the first abstract method. Therefore, the first abstract method is the core.
So let's look at the subclass of InputStream, where FilterInputStream is more special, and this class is constructed
, you need to pass in a InputStream object. The inside Read method is also called the incoming InputStream object to implement, it can be said that this is a decorative class. And the other four subcategories Fileinputstream,bytearrayinputstream
Pipedinputstream,objectinputstream. is to read data from different media, so they have their own unique method to achieve
public abstract int Read () this abstract function.


Okay, here's the Reader,reader system is used to read the character stream.
Similarly, reader also defines several read methods, the most important of which is abstracted
Abstract public int read (char cbuf[], int off, int len) throws IOException;

Take a look at some of the more important sub-classes in reader.

One of the most important subclasses of reader is InputStreamReader, which requires a InputStream object for reader to rely on InputStream to read, and then look at the details, Found to be InputStream
Turns into a streamdecoder, and this streamdecoder can read out the char array in the specified character set. and FileReader integrated InputStreamReader, in fact, just add a construction method, basically the same as InputStream.
Several other types of Stringreader,chararrayreader are constructed by string and char arrays, which are already in a specific character set, so do not go in and out of another reader object. and Buffedreader need to pass in another reader.
To read the characters.

Here is just a brief description of InputStream and reader, and the corresponding Outputstream,writer is also the same.







Java IO stream Analytics

Related Article

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.