来自ZipInputStream的ZipEntry的getInputStream(不使用ZipFile类) [英] getInputStream for a ZipEntry from ZipInputStream (without using the ZipFile class)

查看:1177
本文介绍了来自ZipInputStream的ZipEntry的getInputStream(不使用ZipFile类)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 ZipInputStream ZipEntry InputStream c $ c>不使用 ZipFile 类?

How can I get an InputStream for a ZipEntry from a ZipInputStream without using the ZipFile class?

推荐答案

它有效这样

static InputStream getInputStream(File zip, String entry) throws IOException {
    ZipInputStream zin = new ZipInputStream(new FileInputStream(zip));
    for (ZipEntry e; (e = zin.getNextEntry()) != null;) {
        if (e.getName().equals(entry)) {
            return zin;
        }
    }
    throw new EOFException("Cannot find " + entry);
}

public static void main(String[] args) throws Exception {
    InputStream in = getInputStream(new File("f:/1.zip"), "launch4j/LICENSE.txt");
    Scanner sc = new Scanner(in);
    while(sc.hasNextLine()) {
        System.out.println(sc.nextLine());
    }
    in.close();
}

这篇关于来自ZipInputStream的ZipEntry的getInputStream(不使用ZipFile类)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆