如何以编程方式创建可刷新的zip?

时间:2013-09-24 14:09:58

标签: java android zip zipfile

我有一个压缩类

public class Compress {
  private static final int BUFFER = 80000;

  private String[] _files;
  private String _zipFile;

  public Compress(String[] files, String zipFile) {
    _files = files;
    _zipFile = zipFile;

  }

  public void zip() {
    try  {
      BufferedInputStream origin = null;
      FileOutputStream dest = new FileOutputStream(_zipFile);

      ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));

      byte data[] = new byte[BUFFER];

      for(int i=0; i < _files.length; i++) {
       Log.d("add:",_files[i]);
        Log.v("Compress", "Adding: " + _files[i]);
        FileInputStream fi = new FileInputStream(_files[i]);
        origin = new BufferedInputStream(fi, BUFFER);
        ZipEntry entry = new ZipEntry(_files[i].substring(_files[i].lastIndexOf("/") + 1));
        out.putNextEntry(entry);
        int count;
        while ((count = origin.read(data, 0, BUFFER)) != -1) {
          out.write(data, 0, count);
        }
        origin.close();
      }

      out.close();
    } catch(Exception e) {
      e.printStackTrace();
    }

  }

}

是否可以使用此类创建可刷式拉链?

0 个答案:

没有答案