开发者

A follow-up question for the unzip/zip in Java

开发者 https://www.devze.com 2023-02-16 11:44 出处:网络
I asked a question earlier about unzip/zip using开发者_StackOverflow windows cmd command in Java. That turn out to be not good for a program and one would suggest using the java.util.zip to unzip/zip.

I asked a question earlier about unzip/zip using开发者_StackOverflow windows cmd command in Java. That turn out to be not good for a program and one would suggest using the java.util.zip to unzip/zip. After looking through some tutorial, I found out usually they just loop through the content of the zip file. If I know the name of the file I want, can I extract it explicitly without looping through the whole zip file?? Here in my case, my zip file have 2300+ entries, and I would only want one of them. Do you guys happen to know some tricks? Thank you very much!


You will find hot to decompress files at: http://java.sun.com/developer/technicalArticles/Programming/compression/

Instead of looping and extracting all files just locate file you are interested in with ZipFile.getEntry() method.


You can get a ZipEntry -object for the specific file from ZipFile-object via the getEntry-method. To access the file contents, use ZipFile's getInputStream with the ZipEntry-object.


If this is for yourself and not your program, have you considered using the jar command in the JDK for this?

0

精彩评论

暂无评论...
验证码 换一张
取 消