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