/**
 * 将file文件转换成Byte数组
 * @param file 转换文件
 * @return Byte数组
 */
 public static byte[] getBytesByFile(File file) throws IOException {
 FileInputStream fis = null;
 ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
 try {
 fis = new FileInputStream(file);
 byte[] b = new byte[1000];
 int n;
 while ((n = fis.read(b)) != -1) {
 bos.write(b, 0, n);
 }
 byte[] data = bos.toByteArray();
 return data;
 } catch (Exception e) {
 log.error(“将文件转换成Byte数组失败”, e);
 } finally {
 if (fis != null){
 fis.close();
 }
 bos.close();
 }
 return null;
 }
相关文章
暂无评论...
