(File file)
| 12 | |
| 13 | public class FileUtil { |
| 14 | public static byte[] FileToByte(File file) throws IOException { |
| 15 | // 将数据转为流 |
| 16 | @SuppressWarnings("resource") |
| 17 | InputStream content = new FileInputStream(file); |
| 18 | ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); |
| 19 | byte[] buff = new byte[100]; |
| 20 | int rc = 0; |
| 21 | while ((rc = content.read(buff, 0, 100)) > 0) { |
| 22 | swapStream.write(buff, 0, rc); |
| 23 | } |
| 24 | // 获得二进制数组 |
| 25 | return swapStream.toByteArray(); |
| 26 | } |
| 27 | } |