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();
}