private void copyFileToStream(String filename,String dirname,ZipOutputStream zipper,String comment) throws IOException {
  File file=new File(filename);
  String entryName;
  if (dirname != null) {
    entryName=dirname + "/" + file.getName();
  }
 else {
    entryName=file.getName();
  }
  ZipEntry zipEntry=new ZipEntry(entryName);
  zipEntry.setTime(file.lastModified());
  zipEntry.setSize(file.length());
  if (comment != null) {
    zipEntry.setComment(comment);
  }
  zipper.putNextEntry(zipEntry);
  FileInputStream fis=new FileInputStream(file);
  try {
    int c;
    while ((c=fis.read()) != -1) {
      zipper.write(c);
    }
  }
  finally {
    fis.close();
  }
  zipper.closeEntry();
}

private void copyFileToStream ( String filename , String dirname , ZipOutputStream zipper , String comment ) throws IOException { File file = new File ( filename ) ; String entryName ; if ( dirname != null ) { entryName = dirname + "/" + file . getName ( ) ; } else { entryName = file . getName ( ) ; } ZipEntry zipEntry = new ZipEntry ( entryName ) ; zipEntry . setTime ( file . lastModified ( ) ) ; zipEntry . setSize ( file . length ( ) ) ; if ( comment != null ) { zipEntry . setComment ( comment ) ; } zipper . putNextEntry ( zipEntry ) ; FileInputStream fis = new FileInputStream ( file ) ; try { int c ; while ( ( c = fis . read ( ) ) != - 1 ) { zipper . write ( c ) ; } } finally { fis . close ( ) ; } zipper . closeEntry ( ) ; }
copy a file to an entry in a zip file . the basename of the source file will be used in the zip file , placed in the directory of the zip file specified by dirname . if dirname is null , the file will be placed in the root level of the zip file .
