// create a zip file with one element
// Open the Zip
FileOutputStream fos = new FileOutputStream ( "a.zip" );
ZipOutputStream zip = new ZipOutputStream ( fos );
zip.setLevel( 9 );
zip.setMethod( ZipOutputStream.DEFLATED );

// get the element file we are going to add, using slashes in name.
String elementName = "mydir/thing.txt";
File elementFile = new File ( elementName );

// create the entry
ZipEntry entry = new ZipEntry( elementName );
entry.setTime( elementFile.lastModified() );

// read contents of file we are going to put in the zip
int fileLength = elementFile.length();
FileInputStream fis = new FileInputStream ( elementFile );
byte[] wholeFile = new byte [fileLength];
int bytesRead = fis.read( wholeFile , 0 /* offset */ , fileLength );
// checking bytesRead not shown.
fis.close();

// no need to setCRC, or setSize as they are computed automatically.
zip.putNextEntry( entry );

// write the contents into the zip element
zip.write( wholeFile , 0, fileLength );
zip.closeEntry();

// close the entire zip
zip.close();

