package com.knock.io;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import org.junit.Test;
/**
* @date 160802pm
* 處理流,流的重點,其作用是對節點流的增強,參考裝飾模式
* 本類爲BufferInputStream,其作用是提高效率,輸出流略,
* */
public class KhBuffer {
@Test
public void test(){
File src = new File("D:/test/a.txt");
InputStream is = null;
try {
is = new BufferedInputStream(new FileInputStream(src));
byte[] car = new byte[1024];
int len;
while(-1!=(len=(is.read(car)))){
String str = new String(car,0,len);
System.out.println(str);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
if(null!=is){
is.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
java.se.io.7.緩衝處理流
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.