zip解压缩提取1文件.java

来自「简单的生成一个图片」· Java 代码 · 共 49 行

JAVA
49
字号
package 压缩文件夹.api测试;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class zip解压缩提取1文件
{

	public static void main(String[] args)
	{
	    try {
	        // Open the ZIP file
	        String inFilename = "d://ok.zip";
	        ZipInputStream in = new ZipInputStream(new FileInputStream(inFilename));
	    
	        // Get the first entry

		        ZipEntry entry = in.getNextEntry();
		    
		        // Open the output file
		        String outFilename = "c:\\aa.log";
		        OutputStream out = new FileOutputStream(outFilename);
		    
		        // Transfer bytes from the ZIP file to the output file
		        byte[] buf = new byte[1024];
		        int len;
		        while ((len = in.read(buf)) > 0) 
		        {
		            out.write(buf, 0, len);
		        }
		    
		        // Close the streams
		        out.close();
		        in.close();				

	    } 
	    catch (IOException e)
	    {
	    }


	}

}

⌨️ 快捷键说明

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