好吧,至少,您必须下载归档文件的一部分,直到并包括要提取的文件的压缩数据。这建议采取以下解决方案:打开
URLConnection存档,获取其输入流,将其包装在中
ZipInputStream,然后反复调用
getNextEntry()并
closeEntry()遍历文件中的所有条目,直到找到所需的条目。然后,您可以使用读取其数据
ZipInputStream.read(...)。
Java代码如下所示:
URL url = new URL("http://example.com/path/to/archive");ZipInputStream zin = new ZipInputStream(url.getInputStream());ZipEntry ze = zin.getNextEntry();while (!ze.getName().equals(pathToFile)) { zin.closeEntry(); // not sure whether this is necessary ze = zin.getNextEntry();}byte[] bytes = new byte[ze.getSize()];zin.read(bytes);当然,这是未经测试的。



