我正在尝试读取流并将读取的图像保存为zip文件,因为这将会在多天内运行并且会生成太多的单个文件。如何将图像保存到zip文件
我现在有一个问题,我似乎无法将图像保存到zip文件。下面是我为它制作的工作线程。我确信该图像正在ImageIO.write中。最后的结果是一个空jpgs的zip文件。我想知道是否ImageIO不是将属性写入ZipOutputStream。
感谢您的帮助。
public class ZipSaveWorker implements Runnable{
public static ZipOutputStream out=null;
BufferedImage myImage;
private static int counter=0;
public void run() {
ZipEntry entry=new ZipEntry("video"+counter+".jpg");
counter++;
try {
out.putNextEntry(entry);
ImageIO.write(myImage, ".jpg", out);
} catch (IOException ex) {
Logger.getLogger(ZipSaveWorker.class.getName()).log(Level.SEVERE, null, ex);
}
}
public ZipSaveWorker(BufferedImage image)
{
if (out==null)
{
try {
out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(new File("images" + File.separator + "video.zip"))));
} catch (FileNotFoundException ex) {
Logger.getLogger(ZipSaveWorker.class.getName()).log(Level.SEVERE, null, ex);
}
counter=0;
}
myImage=image;
}
public static void closeStream()
{
try {
out.flush();
out.close();
} catch (IOException ex) {
Logger.getLogger(ZipSaveWorker.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
我会试试看看它今晚是否有效。谢谢。 – Mimyck 2010-08-07 00:52:19