把文件输入流读进 byte数组,返回
1 package io; 2 3 import java.io.BufferedInputStream; 4 import java.io.File; 5 import java.io.FileInputStream; 6 import java.io.FileNotFoundException; 7 import java.io.IOException; 8 9 public class BinaryFile { 10 11 public static byte[] read(File f) throws IOException{ 12 BufferedInputStream bf = new BufferedInputStream 13 (new FileInputStream(f)); 14 //获取文件输入流 15 try { 16 byte[] data = new byte[bf.available()]; 17 // available() 返回估计读取的字节数 18 bf.read(data); 19 return data; 20 } finally { 21 bf.close(); 22 } 23 } 24 25 26 public static byte[] read(String f) throws IOException{ 27 return read(new File(f)); 28 29 } 30 31 32 33 34 35 }