Zipping Files using util.zip No directory

DonPixel

New Member
I have the following situation:I am able to zip my files with the following method:\[code\]public boolean generateZip(){ byte[] application = new byte[100000]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); // These are the files to include in the ZIP file String[] filenames = new String[]{"/subdirectory/index.html", "/subdirectory/webindex.html"}; // Create a buffer for reading the files try { // Create the ZIP file ZipOutputStream out = new ZipOutputStream(baos); // Compress the files for (int i=0; i<filenames.length; i++) { byte[] filedata = http://stackoverflow.com/questions/11298529/VirtualFile.fromRelativePath(filenames).content(); ByteArrayInputStream in = new ByteArrayInputStream(filedata); // Add ZIP entry to output stream. out.putNextEntry(new ZipEntry(filenames)); // Transfer bytes from the file to the ZIP file int len; while ((len = in.read(application)) > 0) { out.write(application, 0, len); } // Complete the entry out.closeEntry(); in.close(); } // Complete the ZIP file out.close(); } catch (IOException e) { System.out.println("There was an error generating ZIP."); e.printStackTrace(); } downloadzip(baos.toByteArray());}\[/code\]This works perfectly and I can download the xy.zip which contains the following directory and file structure:
subdirectory/
----index.html
----webindex.html
My aim is to completely leave out the subdirectory and the zip should only contain the two files. Is there any way to achieve this?(I am using Java on Google App Engine).Thanks in advance
 
Top