ZipEntry的使用

Java中的Java.util.zip.ZipEntry类用于表示ZIP文件条目。

从一个zip文件获取zipEntry的方法是:

private ZipEntry[] getZipEntries2( String file ) throws IOException {
        ZipInputStream zipStream = null;
        ZipEntry zipEntry;
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream( file );
            zipStream = new ZipInputStream( new BufferedInputStream( fileInputStream ) );
            List < ZipEntry > zipEntries = new ArrayList < ZipEntry >();
            while ( ( zipEntry = zipStream.getNextEntry() ) != null && !zipEntry.isDirectory() ) {
                zipEntries.add( zipEntry );
            }
            return zipEntries.toArray( new ZipEntry[zipEntries.size()] );
        }
        finally {
            //关闭流
        }

    }

 

你可能感兴趣的:(java基础-文件流相关)