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

📄 ziptest.java

📁 java应用开发详解
💻 JAVA
字号:
import java.util.*;
import java.text.*;
import java.util.zip.*;
import java.io.*;

public class ZipTest
{
    	public static void main(String[] args)
	{
	
		if (args.length != 2) 
		{
  	   		System.out.println("Usage: java ZipTest <ZipFileName> <ExtractedDirectory>\nExample: java ZipTest a.zip test.txt");
	   		System.exit(1);
		}

     		try
     		{
      			//得到一个ZipFile类
      			ZipFile zf = new ZipFile(args[0]);
      			//有zipFile类生成一个枚举对象
      			Enumeration  es = zf.entries();
      			while(es.hasMoreElements())
      			{                      
      				//得到zip的入口
      				ZipEntry ze = (ZipEntry)es.nextElement();
      				System.out.println("current entry name is "+ze.getName());
      				if (ze.isDirectory())
      				{
      					File ff = new File(args[1],ze.getName());
      					ff.mkdirs();
      				}
      				else
      				{
      					InputStream in = zf.getInputStream(ze);
      					File ff = new File(args[1],ze.getName());
      					File fp = ff.getParentFile();
      					fp.mkdirs();      		     		
      					FileOutputStream fout = new FileOutputStream(ff);      		
      					int c;			    
      					while ((c = in.read()) != -1) fout.write(c);    
      					fout.close();  	
      				}	
      			}     	
      		} 
      		catch(Exception e) 
      		{
          		System.err.println("err:"+e);
          		e.printStackTrace();
      		}
	}
}

⌨️ 快捷键说明

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