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

📄 gzip.java

📁 learning java的源代码。书中每个实例都有相关的代码example。
💻 JAVA
字号:
//file: GZip.javaimport java.io.*;import java.util.zip.*;public class GZip {  public static int sChunk = 8192;  public static void main(String[] args) {    if (args.length != 1) {      System.out.println("Usage: GZip source");      return;    }    // create output stream    String zipname = args[0] + ".gz";    GZIPOutputStream zipout;    try {      FileOutputStream out = new FileOutputStream(zipname);      zipout = new GZIPOutputStream(out);    }    catch (IOException e) {      System.out.println("Couldn't create " + zipname + ".");      return;    }    byte[] buffer = new byte[sChunk];    // compress the file    try {      FileInputStream in = new FileInputStream(args[0]);      int length;      while ((length = in.read(buffer, 0, sChunk)) != -1)        zipout.write(buffer, 0, length);      in.close(  );    }    catch (IOException e) {      System.out.println("Couldn't compress " + args[0] + ".");    }    try { zipout.close(  ); }    catch (IOException e) {}  }}

⌨️ 快捷键说明

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