Monday, March 21, 2011

Writing zip file in java

try {
      FileOutputStream fos = new FileOutputStream("C:\\MyZip.zip");
      ZipOutputStream zos = new ZipOutputStream(fos);
      ZipEntry ze= new ZipEntry("C:\\file1.txt");
      zos.putNextEntry(ze);
      zos.closeEntry();
      
      ze= new ZipEntry("C:\\file2.txt");
      zos.putNextEntry(ze);
      zos.closeEntry();
      zos.close();

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

No comments:

Post a Comment

Chitika