1. 将字节数组转换成图像文件
byte[] byteArray = 要处理的字节数组
InputStream in = new ByteArrayInputStream(byteArray);
BufferedImage img;
try {
img = ImageIO.read(in);
File outputfile = new File("C:\\Temp\\", "testimage.png");
ImageIO.write(img, "png", outputfile);
} catch (IOException e) {
e.printStackTrace();
}
2. 读取压缩文件
byte[] reportZip = 要处理的字节文件数组;
ZipInputStream zis = null;
zis = new ZipInputStream(new ByteArrayInputStream(reportZip));
ZipEntry ze = zis.getNextEntry();
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
int n;
while ((n = zis.read(buffer)) != -1) {
baos.write(buffer, 0, n);
}
// 可以将baos写入输入库,如果是图像,在mysql中需要将字段设置为blob格式
baos.flush();
baos.close();
zis.closeEntry();
zis.close();
读取图像文件
猜你喜欢
转载自yys19781104.iteye.com/blog/2201132
今日推荐
周排行