Results 1 to 2 of 2

Thread: File Output

  1. #1

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228

    Question File Output

    I want to create and write to a zip ( or jar ) file IN CODE. How do i do this... I have a number of image files that i want an application to package into a zip/jar file for me, but i can't find any help on it. Something with the ZipOutputStream i know, but from there I'm lost... help...
    To protect time is to protect everything...

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Code:
    File[] toWrite = new File[4];
    toWrite[0] = new File("c:\\file1.txt");
    toWrite[1] = new File("c:\\file2.txt");
    toWrite[2] = new File("c:\\file3.txt");
    toWrite[3] = new File("c:\\file4.txt");
    
    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("c:\\target.zip"));
    for(int i = 0; i < toWrite.length; ++i) {
      ZipEntry entry = new ZipEntry(toWrite[i].getCanonicalPath());
      entry.setMethod(ZipEntry.DEFLATED);
      // You can set more fields here, like last modification time.
      zos.putNextEntry(entry);
      // Now open an input stream from the original file and
      // copy everything over.
    }
    zos.close();
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width