- 論壇徽章:
- 0
|
想在解壓的時(shí)候,程序就能夠取出壓縮里的文件,然后進(jìn)行其他處理,而不是在寫(xiě)如硬盤(pán)后在去讀取后做相關(guān)處理。
搜索資料后理如下
片段代碼
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.compress.archivers.zip.ZipFile;
ZipInputStream zipInput = new ZipInputStream(is);
DataInputStream dis =null;
try {
ZipEntry entry = zipInput.getNextEntry();
while (entry != null) {
byte[] content = new byte[(int) entry.getSize()];
MyZipFile zipFile = new MyZipFile();
dis = new DataInputStream(zipInput);//用ZIP輸入流構(gòu)建DataInputStream
dis.readFully(content);∥讀取文件內(nèi)容
entry = zipInput.getNextEntry();
}
} finally {
if(dis!=null){
dis.close();
}
if (zipInput != null) {
zipInput.close();
}
if (is != null) {
is.close();
}
} |
|