总结: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) {
		
	}

}

  

相关文章:

  • 2022-12-23
  • 2021-11-10
  • 2021-09-10
  • 2021-11-28
  • 2021-06-11
  • 2022-12-23
  • 2021-03-31
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-17
  • 2021-10-07
  • 2021-09-30
  • 2021-12-29
  • 2021-05-14
相关资源
相似解决方案