//獲取圖片流
FileInputStream fileInputStream = new FileInputStream(new File("C:\\Users\\11841\\Desktop\\zz.jpg"));
int leng;
byte[] b = new byte[1024];
Date date = new Date();
String time = new SimpleDateFormat("yyyy-MM-dd").format(date);
String url = "C:\\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 = DateTime.now().toString("yyyyMMddhhmmss") + ".jpg";
try{
FileImageOutputStream imageOutput = new FileImageOutputStream(new File(url+imgname));//打開輸入流
while ((leng=fileInputStream.read(b))!=-1){
imageOutput.write(b, 0, leng);//將byte寫入硬盤
}
imageOutput.close();
System.out.println("Make Picture success,Please find image in " + url);
} catch(Exception ex) {
System.out.println("Exception: " + ex);
ex.printStackTrace();
}