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[]数组工具类
猜你喜欢
转载自blog.csdn.net/jiulanhao/article/details/80828809
今日推荐
周排行