/**
* 获取文件的流
*/
public static byte[] getBytesFromFile(File file) throws Exception {
FileInputStream fileInputStream = null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
fileInputStream = new FileInputStream(file);
byte[] b = new byte[fileInputStream.available()];
int n = 0;
while ((n = fileInputStream.read(b)) != -1) {
out.write(b, 0, n);
}
return out.toByteArray();
} catch (Exception e) {
throw e;
} finally {
try {
if (fileInputStream != null) {
fileInputStream.close();
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
try {
if (out != null) {
out.close();
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
}
}
获取文件流
最新推荐文章于 2024-05-03 17:32:28 发布