public static byte[] getFileToByte(File file) {
byte[] by = new byte[(int) file.length()];
InputStream is =null;
try {
is = new FileInputStream(file);
ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
byte[] bb = new byte[2048];
int ch;
ch = is.read(bb);
while (ch != -1) {
bytestream.write(bb, 0, ch);
ch = is.read(bb);
}
by = bytestream.toByteArray();
} catch (Exception ex) {
ex.printStackTrace();
}finally {
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return by;
}
IO流----------------将文件转成byte[]数组工具类
最新推荐文章于 2024-09-05 10:29:03 发布