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

📄 zipcompress.java

📁 输入输出程序演示例子
💻 JAVA
字号:
/*
* File Name: ZipCompress.java
* Author:wangch
* Created Date:2004/10/09
* Function Description:Demonstrate the usage of a Zip File
*/
package com.io.zip;
import java.io.*;
import java.util.*;
import java.util.zip.*;
public class  ZipCompress
{
	public static void main(String[] args) throws IOException
	{
    //compress the Zip File
    
		FileOutputStream   of =
      new FileOutputStream("test1.zip");
    CheckedOutputStream cus =
      new CheckedOutputStream(of,new Adler32());
    ZipOutputStream out = 
      new ZipOutputStream(
          new BufferedOutputStream(cus));
    out.setComment("A test of Java Zipping");
    BufferedReader in = 
      new BufferedReader(
        new FileReader(args[0]));
    out.putNextEntry(new ZipEntry(args[0]));//each zip file must at least have  one ZipEntry;
    int c;
    while((c=in.read())!=-1)
      out.write(c);
    in.close();
    out.close();
   
    //Extract the Zip File
    FileInputStream fi =
      new FileInputStream("test1.zip");
    CheckedInputStream csum=
      new CheckedInputStream(fi,new Adler32());
    ZipInputStream zi = 
      new ZipInputStream (
        new BufferedInputStream(csum));
    ZipEntry ze;//You must use ZipEntry to read a zip file
    while((ze=zi.getNextEntry())!=null){
      //System.out.println("Reading file"+ze);
    int x;
    while((x=zi.read()) !=-1)
       System.out.println((char)x);

    
    }
    
    zi.close();
	}
}

⌨️ 快捷键说明

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