/** * Zips a given file. The output ZIP file, by default, is created in the same directory, as the * given input file, and has the same name, as the given input file with 'zip' extension. * * @param file2zip * The file to be zipped. * @return The output ZIP file. * @throws IOException * If any I/O exception occurred. */ public static File zipFile(File file2zip) throws IOException { // construct zipped file path String zipFileName = file2zip.getName(); int extIndex = zipFileName.lastIndexOf('.'); zipFileName = (extIndex >= 0) ? zipFileName.substring(0, extIndex) + ".zip" : zipFileName + ".zip"; File zipFile = new File(file2zip.getParentFile(), zipFileName); return zipFile(file2zip, zipFile); }