利用输出流,生成并在在本地保存图片
作者:互联网
import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.File;
import javax.imageio.stream.FileImageOutputStream;
byte[] ry_zp = (byte[])blob.get("ry_zp");//数据库图片已bolb类型存储,取出来后转成byte数组
Date date = new Date();
String time = new SimpleDateFormat("yyyy-MM-dd").format(date);
String url = "D:\\alarmImages\\"+time+"\\";
System.out.println(url);
File parent = new File(url);
if(!parent.exists()|| !parent.isDirectory()) {
boolean mkdirs = parent.mkdirs();
System.out.println(mkdirs);
}
String imgname = time+ ".jpg";
try{
FileImageOutputStream imageOutput = new FileImageOutputStream(new File(url+imgname));//打开输入流
imageOutput.write(ry_zp, 0, ry_zp.length);//将byte写入硬盘
imageOutput.close();
System.out.println("Make Picture success,Please find image in " + url);
} catch(Exception ex) {
System.out.println("Exception: " + ex);
ex.printStackTrace();
}
标签:输出,url,ry,生成,本地,import,new,zp,out 来源: https://blog.csdn.net/CuiGongZi/article/details/110386316