总结:

FileInputStream fis;

int length;

while((length=fis.read(b,0,b.length))!=-1){

  output.write(b,0,length);

}

}

catch(){

}finally{

if(fis!=null) fis.close();

if(output!=null) output.close();

}

return output.toByteArray();

package com.aini;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.*;

////使用FileInputStream读取文件信息 
public class rt {
	public static byte[] getByte(File file) throws Exception {
		FileInputStream fis = null;
		ByteArrayOutputStream fd = new ByteArrayOutputStream();
		try {
			fis = new FileInputStream(file); // 写入文件
			byte[] b = new byte[6];
			int i;
			while ((i = fis.read(b, 0, b.length)) != -1) {
				fd.write(b, 0, i);
			}

		} catch (Exception E) {
			System.out.println("Error occur during " + file.getAbsoluteFile());
		} finally {
			if (fis != null)
				fis.close();
			if (fd != null)
				fd.close();
		}
		return fd.toByteArray();// 最后一步返回

	}
}

  

相关文章:

  • 2021-07-25
  • 2021-09-06
  • 2021-10-05
  • 2021-09-09
  • 2021-04-16
  • 2021-07-23
猜你喜欢
  • 2021-07-12
  • 2021-05-22
  • 2022-02-04
  • 2021-08-07
  • 2022-12-23
  • 2021-08-12
  • 2021-05-24
相关资源
相似解决方案