I have a page that will generate a zip file from the users selected files(checkbox).
Here is the code:
if(counter >= MAXFILES){counter=0;}
outFilename = "C:\\ZIP\\OK"+counter+".zip";
counter++;
ZipOutputStream outfile = new ZipOutputStream(new FileOutputStream(outFilename));
// Compress the files
for (int i=0; i<filenames.length; i++) {
FileInputStream in = new FileInputStream(PATH+filenames[i]);
// Add ZIP entry to output stream.
outfile.putNextEntry(new ZipEntry(PATH+filenames[i]));
// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buf)) > 0) {
outfile.write(buf, 0, len);
}
// Complete the entry
outfile.closeEntry();
in.close();
}
// Complete the ZIP file
outfile.close();
} catch (IOException e) {
}
}%>
It works fine, except that when the user selects a file that contains whitespaces in the name ( file Name.txt). When a file with naming conventions as above is added to the FileInputStream the resulting zip file is corrupted(winzip wont open it)[file does not appear to be a valid zip archive]is what the winzip error is.
Anyone know why whitespaced file names will cause this? Is there a solution?
Thanks in advance!!