Java source FileInputStream

Source: Internet
Author: User
Tags abstract stringbuffer

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;

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.