import org.apache.commons.compress.archivers.ArchiveEntry; 
import org.apache.commons.compress.archivers.zip.Zip64Mode; 
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; 
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; 
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; 

解决方案 »

  1.   

    要确认相关的jar文件是否导入了
      

  2.   

    导入的jar包错了。大神们有这个jar包没 ? 
      

  3.   


    import org.apache.tools.zip.ZipEntry;
    import org.apache.tools.zip.ZipOutputStream;
    /**
         * 压缩文件
         * @param filePaths 存放文件物理路径的集合
         * @param fileNames 文件的名称(和文件路径对应,可以是中文)
         * @param outPath 压缩文件的输出路径(物理路径)
         */
        public void reduceFile(List<String> filePaths, List<String> fileNames, String outPath) {
            if (null != filePaths && filePaths.size() > 0 && null != fileNames && fileNames.size()== filePaths.size()) {
                try {
                    OutputStream fileOutput = new FileOutputStream(outPath);
                    ZipOutputStream zipOutput = new ZipOutputStream(fileOutput);
                    for (int i = 0; i < filePaths.size(); i++) {
                        File file = new File(filePaths.get(i));
                        if (file.exists() && !file.isDirectory()) {
                            InputStream input = new FileInputStream(file);
                            ZipEntry entry = new ZipEntry(fileNames.get(i));
                            zipOutput.putNextEntry(entry);
                            int length = 0;
                            while ((length = input.read()) != -1) {
                                zipOutput.write(length);
                            }
                            input.close();
                        }
                    }
                    zipOutput.setEncoding("GBK");
                    zipOutput.flush();
                    zipOutput.closeEntry();
                    zipOutput.close();
                    fileOutput.flush();
                    fileOutput.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }