Overall summary of Io streams

Source: Internet
Author: User

 

Overall summary of Io streams

The decoration mode has four roles: universal interface, primitive, abstract decoration,

The specific decoration, because it is to aggregate the original to the decoration, so you can inject the original or decoration through the constructor

Another decoration, Multiple decorations can be combined at will to form a comprehensive functional object.

Io streams are divided into input streams and output streams. Input streams are files to memory, and output streams are memory to files.

Streams are divided into low-level streams and high-level streams. when instantiating a high-level stream, you must construct a subaccount to inject the low-level stream to the high-level stream.

Streaming. The common input stream methods include read (), read (char []), read (byte []), Readline, and output stream.

The common methods are write (INT), write (byte []), write [char [], and print ("string ").

When reading a file, for a byte/byte array, the ending condition for reading the character/character array is! =-1,

The ending condition for reading strings is! = NULL. If you want to write cached output to a file

Must be flush or close.

Architecture of the input byte stream

Inputstream

Fileinputstream filterinputstream

Objectinputstream datainputstream bufferedinputstream

Implementation Code:

-- Read a byte

Int temp = FCM. Read ();

While (temp! =-1)

{

System. Out. Print (temp );

Temp = FCM. Read ();

}

-- Read a batch of bytes

Byte [] bytes = new byte [1, 1000];

Int result = FCM. Read (bytes );

While (result! =-1)

{

String temp = new string (bytes, 0, result );

Result = FCM. Read (bytes );

}

Output byte stream:

Outputstream

Fileoutputstream filteroutputstreame

Objectoutputstream bufferedoutputstream dataoutputstream printstream

Output byte stream code:

Int temp;

FS. Write (temp );

Byte temps [] = new byte [2, 1000];

FOS. Write (temps );

Input response stream

Reader

Filereader inputstreamreader (converts byte streams into bytes streams)

Bufferedreader (with cache)

Input merge stream implementation

Bufferedreader BR = new bufferedreader (New inputstreamreader (system. In ));

String temp = Br. Readline ();

While (temp! = NULL)

{

Temp = Br. Readline ();

}

Output Response stream:

Writer

Filewriter outputstreamwriter

Bufferedwriter printwriter

Output the response stream code:

FW. Write (INT)

FW. Write (char [])

FW. Write ("string ");

Printstream, bufferedwriter, and printwriter

Printstream: A byte stream that can print bytes or print arrays,

Do not close or flush, E. printstacktrace ()

System. Out. println () is its instance.

Bufferedwriter and printwriter: A bytes stream. They can only print characters or strings.

Because there is a cache, to write files, you must close or flush

 

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.