Java Summary of the container

Source: Internet
Author: User

"Java streaming input/output principle"
In the JAAV program, the input/output operation for the data is "streamed" (stream); J2SDK provides various


A variety of "stream" classes to obtain different kinds of data, in the program through the standard method of input or output data.
"Classification of input/output streams"
Several types of Liu (dirty abstract class) are defined in the Java.io package to achieve the input/output function, from different angles


To classify it:
Depending on the direction of the data flow, it can be divided into input stream and output stream.
The case processing data units can be divided into byte stream and character stream.
According to the different functions can be divided into node Liu and processing flow.
All stream types provided by J2SDK are inherited from the following four abstract stream types in the package java.io.
|------------------------------------||        |     byte Stream    |   Character Stream  | | --------|---------------|-----------|| Input Stream |  InputStream  |   Reader  | | --------|---------------|-----------|| Output Stream | OutputStream  |   Writer  | | ------------------------------------|


"Node stream and process Flow"
A node stream is the ability to read and write data (for example, files, memory) from a specific data source (node).
The processing flow is a "link" in the existing stream (node flow and processing flow) IQ, through the processing of data for the program to provide more


For powerful reading and writing functions.
"The basic method of InputStream"
Reads a byte and returns it as a certificate (0~255),
If 1 is returned to the end of the input stream
int read () throws IOException


Reads a series of bytes and stores it to an array of buffer,
Anti-Hi more than 10 degrees to go to the number of bytes, if read before the end of the input stream returned-1
int read (byte[] buffer) throws IOException


Reads the length of bytes
and stored in a byte array buffer, starting from the length position
Returns the number of bytes to go more than 10 degrees, if read before the end of the input stream returns-1
int read (byte[] buffer,int offset,int length) throws IOException


Close stream frees memory resource
void Close () throws IOException


Skips n bytes without reading, returns the number of bytes skipped in the time
Long Skip (long N) throws IOException


"The basic method of OutputStream"
Writes a byte data to the output stream, which is the low 8 bits of parameter B
void write (int b) throws IOException


Writes data from a byte-type array to the output stream
void Write (byte[] b) throws IOException


That starts at the specified position (off) in an array of byte types.
Len bytes written to the output stream
void Write (byte[] B,int off,int len) throws IOException


Turn off freeing memory resources
void Close () throws IOException


Writes all buffered data from the output stream to the destination
void Flush () throws IOException
"The basic method of reader"
Reads a character and returns the form of an integer (0~255)
If 1 is returned to the end of the input stream
int read () throws IOException


Reads a length character
and stored in an array buffer, starting with the length position
Returns the number of characters that are more than 10 degrees away, if the read was before the end of the input stream-1
int read (char[] cbuf,int offset,int length) throws IOException


Close stream frees memory resource
void Close () throws IOException


Skips n characters without reading, returns the number of bytes in the time bar
Long Skip (long N) throws IOException
"The basic method of writer"
You want to write a character data in the output stream, which is the lower 16 bits of parameter B
void write (int c) throws IOException


Writes data from an array of character types to the output stream
void Write (char[] cbuf) throws IOException


The total of an array of character types starts at the specified position (offset).
Length of characters written to the output stream
void Write (char[] cbuf,int offset,int length) throws IOException


Turn off freeing memory resources
void Close () throws IOException


Writes all buffered data from the output stream to the destination
void Flush () throws IOException
"Access File"
FileInputStream and FileOutputStream inherit from InputStream and OutputStream respectively.


Input and output bytes to the file.
Common construction methods for FileInputStream and FileOutputStream:
FileInputStream (String name) throws FileNotFoundException
FileInputStream (file file) throws FileNotFoundException
FileOutputStream (String name) throws FileNotFoundException
FileOutputStream (file file) throws FileNotFoundException
FileOutputStream (File File,boolean append) throws FileNotFoundException
The FileInputStream and FileOutputStream classes support their parent classes InputStream and OutputStream


The data read and write method provided.
Attention:
The FileInputStream and FileOutputStream streams are instantiated with a Try-catch statement that handles their possible throw


Out of the FileNotFoundException.
The Try-catch statement is also used when reading and writing data to handle the IOException that may be thrown.
FileNotFoundException is a subclass of IOException.
"Buffered Stream"
Buffer stream to "socket" on the corresponding node Liu, read and write data to provide a buffer function, improve the read and write


, while adding some new methods.
The J2SDK provides four buffer streams, which are commonly constructed by:
BufferedReader (Reader in)
BufferedReader (Reader in,int sz)//sz is the size of the custom buffer
Bufferedwriterwriter (Writer out)
BufferedWriter (Writer out,int SZ)
Bufferedinputstream (InputStream in)
Bufferedinputstream (inputstream in,int size)
Bufferedoutputstream (OutputStream out)
Bufferedoutputstream (outputstream out,int size)
The buffer input stream supports the mark and reset methods of its parent class.
Bufferreader provides a ReadLine method for reading a line of strings, separated by \ R or \ n.
BufferedWriter provides the newline for writing a line delimiter.
For the buffered stream of output, the written data is now cached in memory, and using the Flush method will make the in-memory data


Write it right away.
"Convert Stream"
InputStreamReader and OutputStreamWriter are used for conversion between byte data and character data.
InputStreamReader need and InputStream "socket".
OutputStreamWriter need and OutputStream "socket".
A transform stream can specify its encoding collection at construction time, for example:
InputStream ISR = new InputStreamReader (system.in, "Iso8859_1")
"Data Flow"
DataInputStream and DataOutputStream inherit from InputStream and OutputStream, respectively, and it


belongs to the processing stream, which needs to be "sockets" on the InputStream and OutputStream-type node streams, respectively.
DataInputStream and DataOutputStream provide access to machine-independent Java RAW type data


(such as: int,double, etc.) method.
DataInputStream and DataOutputStream are constructed by:
DataInputStream (InputStream in)
DataOutputStream (Outputstrewam out)
"Print Stream"
Both PrintWriter and printstream are output streams, respectively, for characters and bytes.
Pritnwriter and Pritnstream provide the overloaded print
The Println method is used for the output of a variety of data.
PrintWriter and PrintStream output operations do not throw an exception and the user gets an error by detecting an error state


Information.
PrintWriter and PrintStream have automatic flush function.
PrintWriter (Writer out)
PrintWriter (Writer Out,boolean AutoFlush)
PrintWriter (OutputStream out)
PrintWriter (OutputStream Out,boolean AutoFlush)
PrintStream (OutputStream out)
PrintStream (OutputStream Out,boolean AutoFlush)
"Object Flow"
Writes or reads an object directly
Transient keywords
Serializable interface
Externalizable interface

Java Summary of the container

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.