java io工具 文件转二进制byte数组
把文件输入流读进 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 }
posted on 2018-06-07 13:39 wait_for_you 阅读(836) 评论(0) 编辑 收藏 举报