Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 985061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:06:40+00:00 2026-05-16T05:06:40+00:00

I am attempting to read in a stream and save the read images to

  • 0

I am attempting to read in a stream and save the read images to a zip file as this is going to be running over multiple days and would generate far too many individual files.

I now have an issue where I seem to be unable to save images into a zip file. The worker thread I have built for it is below. I am sure that the image is making it to the ImageIO.write. The result at the end however is a zip file of empty jpgs. I am wondering if perhaps ImageIO is not writing property to the ZipOutputStream.

Thanks for your help.

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


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:06:40+00:00Added an answer on May 16, 2026 at 5:06 am

    The error in your code is in the line:

    ImageIO.write(myImage, ".jpg", out);
    

    It should be:

    ImageIO.write(myImage, "jpg", out);
    

    I am also not sure if you should call closeEntry() after every image has been written.

    Consider what Stephen C writes, this code could result in corrupt zip files if the power was cut or the VM died. Consider making backups of the zip files a few times a week, maybe even a few times a day, to ensure your multiple day runs aren’t completely ruined (I assume a run can be resumed).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In attempting to read the source code for the csv.py file (as a guide
I am attempting to read a text file into a linear linked list of
Using Qt, I'm attempting to read the contents of the stdin stream in a
I am attempting to read an image file, as a base64 encoded string and
I am attempting to read from a url into a System.IO.Stream object. I tried
I would like to read all content that's been written to the output stream.
I'm attempting to read a file (particularly /proc/stat) to get data out of it.
I am attempting to read a WSDL page, similar to this http://schemas.xmlsoap.org/wsdl/ I am
I am attempting to write an Android app which will allow me to read
I'm receiving an error when I'm attempting to consume a web service: Cannot read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.