Results 1 to 2 of 2
  1. #1
    mglover is offline Member
    Join Date
    Jun 2010
    Posts
    1
    Rep Power
    0

    Default How do I store images in a zip file in Java

    Hi,

    I am trying to write some code to collect a load of images from URLs and then to store them in a zip file. So I have written code to get each image into an Image object thus:-

    // create the zip file/stream
    FileOutputStream dest = new FileOutputStream("d://images.zip");
    out = new ZipOutputStream(new BufferedOutputStream(dest));

    while ( (record=dis.readLine()) != null ) { // This is reading a text file containing the list of images

    String URLStr = UrlStem + record;
    URL url = new URL(URLStr);
    URLConnection urlconnection = url.openConnection();
    image = ImageIO.read(url);

    // Now want to add this image to a zip file - but how??
    ...
    }

    but I can't see how to then how to add it to a zip file. The images might be GIFs or JPEGS. I have seen examples of adding files from a directory but not of doing it on the fly - is it possible?

    Thanks in advance

  2. #2
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    305
    Rep Power
    6

    Default

    As long as you know what type the file is at the time you are writing it, I don't see why you can't do it on the fly. Just create the ZipEntry with the known extension and write the bytes to that

Similar Threads

  1. store data into an array from a file
    By chopo1980 in forum New To Java
    Replies: 10
    Last Post: 11-13-2009, 09:48 AM
  2. how to store string in text file
    By santhosh_el in forum AWT / Swing
    Replies: 2
    Last Post: 04-03-2009, 06:21 AM
  3. Replies: 3
    Last Post: 04-07-2008, 06:02 PM
  4. How to store property file into key value pair
    By Java Tip in forum java.util
    Replies: 0
    Last Post: 04-05-2008, 10:16 AM
  5. store file
    By kazitula in forum Java Applets
    Replies: 0
    Last Post: 02-17-2008, 09:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •