java - 从 ZipInputStream 获取 ZipEntry 的 getInputStream(不使用 ZipFile 类)

标签 java inputstream zip zipinputstream

如何在不使用 ZipFile 类的情况下从 ZipInputStream 获取 ZipEntryInputStream

最佳答案

它是这样工作的

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();
}

关于java - 从 ZipInputStream 获取 ZipEntry 的 getInputStream(不使用 ZipFile 类),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14603319/

相关文章:

Java Socket - read() 方法如何知道是否已到达流的末尾?

java - 使用 ZipFileSystem 压缩一个巨大的文件夹会导致 OutOfMemoryError

java - Jackson NoSuchMethodError requirePropertyOrdering maven 在运行时使用 google app engine 项目

java - 使用android中的添加按钮动态地将editTexts添加到布局

c++ - 如何在 C++ 中将用户输入限制为数字和字母

c++ - 如何从输入文件中添加和删除用户到linux系统?

powershell - 无法使用 System.IO.Compression.FileSystem.dll

Python shutil.make_archive() 在 Windows 上创建点目录

java - 检索 jscrollpane 中包含的 jtable 的已更改内容

java - 如何检查作业是否在 Quartz 框架中运行