java读取.apk(zip)文件的子文件各种信息!

2018-10-17  本文已影响89人  林伯任

package com.jwis.katch;

import java.io.File;
import java.io.IOException;
import java.util.Enumeration;

import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;

public class readZipFile {

public static void readZipFile2(File file) { 
    try { 
        ZipFile zipfile = new ZipFile(file); //创建ZipFile对象
        System.out.println(zipfile.getName()); //打印Zip文件路径
        System.out.println("ZIP条目数:" + zipfile.size()); //打印Zip文件条目数
         
        Enumeration<? extends ZipEntry> en = zipfile.entries(); 
        ZipEntry entry; 
        while(en.hasMoreElements()) { 
            entry = (ZipEntry) en.nextElement(); 
            System.out.println(entry.getName()); 
        } 
        zipfile.close(); 
    }catch(ZipException e) { 
        System.out.println(file.getName() + "压缩文件错误"); 
    }catch(IOException e) { 
        System.out.println(file.getName() + "读取文件时出错"); 
    } 
} 

public static void main(String[] args) {
    File fileTest = new File("D:\\11\\11.zip");
    readZipFile2(fileTest);
}

}

上一篇下一篇

猜你喜欢

热点阅读