⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compress.java

📁 cwbbs 云网论坛源码
💻 JAVA
字号:
package cn.js.fan.util.file;import java.io.*;import java.util.zip.*;import cn.js.fan.util.*;public class Compress {  public static void gzipFile(String from, String to) throws IOException {    FileInputStream in = new FileInputStream(from);    ZipEntry entry = new ZipEntry(from);    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(to));    out.putNextEntry(entry);    byte[] buffer = new byte[4096];    int bytes_read;    while ( (bytes_read = in.read(buffer)) != -1)      out.write(buffer, 0, bytes_read);    in.close();    out.close();  }  public static void zipDirectory(String dir, String zipfile) throws      IOException, IllegalArgumentException {    ZipOutputStream out =        new ZipOutputStream(new FileOutputStream(zipfile));    zipDir(out, dir);    out.close();  }  public static void zipDir(ZipOutputStream out, String dir) throws IOException,      IllegalArgumentException {    File d = new File(dir);    if (!d.isDirectory()) {      byte[] buffer = new byte[4096];      int bytes_read;      FileInputStream in = new FileInputStream(d);      ZipEntry entry = new ZipEntry(StrUtil.GBToUnicode(dir));      out.putNextEntry(entry);      while ( (bytes_read = in.read(buffer)) != -1)        out.write(buffer, 0, bytes_read);            in.close();      return;    }        String[] entries = d.list();    String path = d.getPath();    for (int i = 0; i < entries.length; i++) {      zipDir(out, path + "/" + entries[i]);    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -