Close to do a very simple function, to two return values, I intend to have a class encapsulated a return, then the leader asked to use StringBuilder return, do not stringbuffer, because the local variable StringBuffer finally to compile to StringBuilder Because StringBuilder does not have any synchronization.
Ask everybody's opinion, the wind South said InputStream int read (byte[] b) reads a certain number of bytes from the input stream and stores it in buffer array B, which is similar, it seems necessary to study IO.
An important function in the InputStream class, with only one abstract useful,
public abstract int Read () throws IOException;
The other two read are of little significance.
public int read(byte b[], int off, int len) throws IOException 和
public int read(byte b[]) throws IOException {
return read(b, 0, b.length);
}
Here's a look at the implementation of its subclass FileInputStream,
/* File Descriptor-handle to the open file */
Private FileDescriptor FD;
This is very important, this is a file handle, C language using the Fopen function is known.
/**
* Opens the specified file for reading.
* @param name the name of the file
*/
private native void open(String name) throws FileNotFoundException;
/**
* Reads a byte of data from this input stream. This method blocks
* if no input is yet available.
*
* @return the next byte of data, or <code>-1</code> if the end of the
* file is reached.
* @exception IOException if an I/O error occurs.
*/
public native int read() throws IOException;
/**
* Reads a subarray as a sequence of bytes.
* @param b the data to be written
* @param off the start offset in the data
* @param len the number of bytes that are written
* @exception IOException If an I/O error has occurred.
*/
Private native int Readbytes (byte b[], int off, int len) throws IOException;