欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java解压缩zip文件代码,java解压缩zip,下面示例代码演示解压缩z

来源: javaer 分享于  点击 34651 次 点评:233

java解压缩zip文件代码,java解压缩zip,下面示例代码演示解压缩z


下面示例代码演示解压缩zip文件,该zip文件只包含一个文件:

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;/** * * @author byrx.net */public class Main {    /**     * 解压zip文件     */    public void extractZipFile() {        try {            String zipFileName = "compressed.zip";            String extractedFileName = "extracted.txt";            //Create input and output streams            ZipInputStream inStream = new ZipInputStream(new FileInputStream(zipFileName));            OutputStream outStream = new FileOutputStream(extractedFileName);            ZipEntry entry;            byte[] buffer = new byte[1024];            int nrBytesRead;            //Get next zip entry and start reading data            if ((entry = inStream.getNextEntry()) != null) {                while ((nrBytesRead = inStream.read(buffer)) > 0) {                    outStream.write(buffer, 0, nrBytesRead);                }            }            //Finish off by closing the streams            outStream.close();            inStream.close();        } catch (IOException ex) {            ex.printStackTrace();        }    }    /**     * @param args the command line arguments     */    public static void main(String[] args) {        new Main().extractZipFile();    }}
相关栏目:

用户点评