Zipping files that contain special characters
From UbikWiki
Contents |
Usage
You want to zip files that contain international characters (é,ç,è, chinese characters).
Default Java ZipFileOutputStream will not allow you to do it (unless until JDK 5).
Dependency
Use [TrueZip]
Code
Java code to zip an array of files:
/** * Zips a set of files or folders using the base folder * @param outFile Target zip * @param inputFiles Files or folders to be included in the zip * @return File generated file * @throws TechniqueException */ public static final File zipFiles(File outFile, File[] inputFiles) throws TechniqueException { ZipOutputStream out = null; try { File base = computeBaseFolder(inputFiles); if (base != null) { base = base.isDirectory() ? base : base.getParentFile(); } // Create the ZIP file out = new ZipOutputStream(new FileOutputStream(outFile .getAbsolutePath()), "IBM437"); zipFilesIntoStream(base, out, inputFiles); return outFile; } catch(IOException e) { throw new TechniqueException( "Error creating zip file " + outFile.getAbsolutePath() + " including files:" + Arrays.asList(inputFiles),e); } finally { if (out != null) { try { out.close(); } catch (IOException e1) { ; } } } }
Authors
- Philippe Mouawad