猿问

java中的io流问题 FileInputStream中的read()返回的int类型是读取字节的

java中的io流问题
FileInputStream中的read()返回的int类型是读取字节的ASCLL编码么?是一个一个字节读?
BufferedInputStream中的read()返回的是读入字节的长度吗?是一段一段的读吗?谢谢了,感觉好疑惑

慕尼黑5688855
浏览 1354回答 3
3回答

慕运维8079593

不是,两个都是返回Ascll编码,bufferInputStream是缓冲流,提高效率

蝴蝶刀刀

FileInputStream是基础类,字节流,按字节读取。BufferedInputStream是包装类,处理流,先将数据读于缓冲区,然后再读取

千巷猫影

看源码啊,FileInputStream/*** 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;BufferedInputStream/*** See* the general contract of the <code>read</code>* method of <code>InputStream</code>.** @return the next byte of data, or <code>-1</code> if the end of the* stream is reached.* @exception IOException if this input stream has been closed by* invoking its {@link #close()} method,* or an I/O error occurs.* @see java.io.FilterInputStream#in*/public synchronized int read() throws IOException {if (pos >= count) {fill();if (pos >= count)return -1;}return getBufIfOpen()[pos++] & 0xff;}
随时随地看视频慕课网APP

相关分类

Java
我要回答