<b>java源码FileInputStream</b>[Java编程]
本文“<b>java源码FileInputStream</b>[Java编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
近做一个很简单的函数,要两个返回值,我打算有一个类封装一下返回,后来带领要求利用StringBuilder返回,不用StringBuffer,因为部分变量StringBuffer最后还是要编译为StringBuilder,因为StringBuilder没有任何同步.
问了一下大家的见解,风南说InputStream 的int read(byte[] b) 从输入流中读取一定数目的字节并将其存储在缓冲区数组 b 中,也是近似的,看来有必要研究一下IO了.
InputStream类中重要的函数,只有一个抽象的有效,
public abstract int read() throws IOException;
其他两个read的意义不大.
public int read(byte b[], int off, int len) throws IOException 和
public int read(byte b[]) throws IOException {
return read(b, 0, b.length);
}
下面看它的子类FileInputStream的实现,
/* File Descriptor - handle to the open file */
private FileDescriptor fd;
这个很重要,这是文件句柄,C语言利用fopen函数的都知道.
/**
* 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;
以上是“<b>java源码FileInputStream</b>[Java编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |