中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Java采用zip壓縮文件代碼示例

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
import java.util.zip.*;
import java.io.*;

public class ZipIt {
  public static void main(String args[]) throws IOException {
    if (args.length < 2) {
      System.err.println("usage: java ZipIt Zip.zip file1 file2 file3");
      System.exit(-1);
    }
    File zipFile = new File(args[0]);
    if (zipFile.exists()) {
      System.err.println("Zip file already exists, please try another");
      System.exit(-2);
    }
    FileOutputStream fos = new FileOutputStream(zipFile);
    ZipOutputStream zos = new ZipOutputStream(fos);
    int bytesRead;
    byte[] buffer = new byte[1024];
    CRC32 crc = new CRC32();
    for (int i=1, n=args.length; i < n; i++) {
      String name = args[i];
      File file = new File(name);
      if (!file.exists()) {
        System.err.println("Skipping: " + name);
        continue;
      }
      BufferedInputStream bis = new BufferedInputStream(
      new FileInputStream(file));
      crc.reset();
      while ((bytesRead = bis.read(buffer)) != -1) {
        crc.update(buffer, 0, bytesRead);
      }
      bis.close();
      // Reset to beginning of input stream
      bis = new BufferedInputStream(
      new FileInputStream(file));
      ZipEntry entry = new ZipEntry(name);
      entry.setMethod(ZipEntry.STORED);
      entry.setCompressedSize(file.length());
      entry.setSize(file.length());
      entry.setCrc(crc.getValue());
      zos.putNextEntry(entry);
      while ((bytesRead = bis.read(buffer)) != -1) {
        zos.write(buffer, 0, bytesRead);
      }
      bis.close();
    }
    zos.close();
  }
}

標簽:

版權申明:本站文章部分自網(wǎng)絡,如有侵權,請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:java實現(xiàn)根據(jù)域名獲得ip地址代碼

下一篇:使用單例模式實現(xiàn)mysql類