BufferedInputStream
生活随笔
收集整理的這篇文章主要介紹了
BufferedInputStream
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
BufferedInputStream:緩沖字節(jié)輸入流,是一個高級流(處理流),與其他低級流配合使用。
查看源碼可見?BufferedInputStream 沒有無參構造方法,它必須傳入一個IputStream 一般是FileInputStream。
/*** 創(chuàng)建一個 BufferedInputStream 并保存其參數(shù),即輸入流 in,以便將來使用。創(chuàng)建一個內部緩沖區(qū)數(shù)組并將其存儲在
*buf 中,該buf的大小默認為8192。
*/ public BufferedInputStream(InputStream in) {
this(in, DEFAULT_BUFFER_SIZE);
} /**
* 創(chuàng)建具有指定緩沖區(qū)大小的 BufferedInputStream 并保存其參數(shù),即輸入流 in,以便將來使用。創(chuàng)建一個長度為
*size 的內部緩沖區(qū)數(shù)組并將其存儲在 buf 中
*/ public BufferedInputStream(InputStream in, int size) {
super(in);
if (size <= 0) {
throw new IllegalArgumentException("Buffer size <= 0");
}
buf = new byte[size];
}
常用方法
//從該輸入流中讀取一個字節(jié)
public synchronized int read() throws IOException {
if (pos >= count) {
fill();
if (pos >= count)
return -1;
}
return getBufIfOpen()[pos++] & 0xff;
} //從此字節(jié)輸入流中給定偏移量處開始將各字節(jié)讀取到指定的 byte 數(shù)組中。
public int read1(byte[] b,int off,int len) throws IOException{xxxxx}
轉載于:https://www.cnblogs.com/z0909y/p/9242902.html
總結
以上是生活随笔為你收集整理的BufferedInputStream的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jQuery 效果 - 动画 anima
- 下一篇: 7、Flask实战第7天:Jinjia2