i 绝望

依然

Miss Lang

java代码i/o流类

总结:BufferedInputStream();

package com.aini;

import java.io.*;
//使用BufferedInputStream读取文件
public class yhtrds {
	//这是一个方法
	public static byte[] readFileByBufferedInputStream(File file){
		
		BufferedInputStream bis;
		FileInputStream fis;
		ByteArrayOutputStream ot=new ByteArrayOutputStream();//字节数组输出流
		try{//代码块,正常的。
		fis=new FileInputStream(file);
		bis=new BufferedInputStream(fis);
		byte []b=new byte[1023];
		int length;
		while((length=bis.read(b,0,b.length))!=-1){
		      ot.write(b,0,length);
		}
			
		}catch(Exception e){
			
			System.out.println("Error occurs during reading:"+file.getAbsoluteFile());
		}finally{
			
			if(fis!=null) fis.close();
			if(bis!=null) bis.close();
			if(ot!=null) ot.close();//这里有错误,威慑么
		}
		return ot.toByteArray();
	}
	public static void main(String[] args) {
		
	}

}

  

posted on 2013-11-10 20:54  juewang  阅读(202)  评论(0编辑  收藏  举报

绝望依然

Miss Lang