如题 ,希望能详细点!!

解决方案 »

  1.   

    public static void doZipCompress(String compressFileName, String originalFileName, InputStream inputStream) throws Exception {
    File newFile = new File(compressFileName);
    if (newFile.exists()) {
    newFile.delete();
    }
    newFile.createNewFile();
    ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(newFile));
    byte[] data = new byte[1024];
    ZipEntry entry = new ZipEntry(originalFileName);
    zipOut.putNextEntry(entry);
    int n;
    while (-1 != (n = inputStream.read(data))) {
    zipOut.write(data, 0, n);
    }
    zipOut.close();
    }希望对你有所帮助,很简单,没什么其它功能
      

  2.   

    /**
     * 
     * @param inputFileName
     *            输入一个文件夹
     * @param zipFileName
     *            输出一个压缩文件夹,打包后文件名字
     * @throws Exception
     */
    public void zip(String inputFileName, String zipFileName) throws Exception {
    zip(zipFileName, new File(inputFileName));
    }

    private void zip(String zipFileName, File inputFile) throws Exception {
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName));
    zip(out, inputFile, "");
    out.close();
    }

    private void zip(ZipOutputStream out, File f, String base) throws Exception {
    /*读取进度*/
    if (f.isDirectory()) { // 判断是否为目录
    File[] fl = f.listFiles();
    out.putNextEntry(new org.apache.tools.zip.ZipEntry(base + "/"));
    base = base.length() == 0 ? "" : base + "/";
    for (int i = 0; i < fl.length; i++) {
    showSize += fl[i].length();
    setMsg("已压缩" + (showSize * 100 / totalSize ) + "%......", false);
    zip(out, fl[i], base + fl[i].getName());


    }
    } else { // 压缩目录中的所有文件
    out.putNextEntry(new org.apache.tools.zip.ZipEntry(base));
    FileInputStream in = new FileInputStream(f);
    int b;
    while ((b = in.read()) != -1) {
    out.write(b);
    }
    in.close();
    }
    }
      

  3.   

    里面的showSize()是什么方法啊
      

  4.   

    说错了 showSize 和 totalSize是什么啊
      

  5.   

    说错了 showSize 和 totalSize是什么啊
      

  6.   

    showSize 和 totalSize是什么啊
    是我显示进度条的