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

java使用java.util.zip列出压缩文件中的文件列表,javajava.util.zip,package com.

来源: javaer 分享于  点击 38615 次 点评:242

java使用java.util.zip列出压缩文件中的文件列表,javajava.util.zip,package com.


package com.javacodegeeks.snippets.core;import java.io.IOException;import java.util.Enumeration;import java.util.zip.ZipEntry;import java.util.zip.ZipFile;public class ListContentsOfZipFile {    public static void main(String[] args) {        ZipFile zipFile = null;        try {            // open a zip file for reading            zipFile = new ZipFile("c:/archive.zip");            // get an enumeration of the ZIP file entries            Enumeration<? extends ZipEntry> e = zipFile.entries();            while (e.hasMoreElements()) {                ZipEntry entry = e.nextElement();                // get the name of the entry                String entryName = entry.getName();                System.out.println("ZIP Entry: " + entryName);            }        }        catch (IOException ioe) {            System.out.println("Error opening zip file" + ioe);        }         finally {             try {                 if (zipFile!=null) {                     zipFile.close();                 }             }             catch (IOException ioe) {                    System.out.println("Error while closing zip file" + ioe);             }         }    }}
相关栏目:

用户点评