总结:

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();// 最后一步返回 }
}

  

05-11 22:43