程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> JAVA解壓壓縮包實現代碼

JAVA解壓壓縮包實現代碼

編輯:關於JAVA
 

Java解壓ZIP壓縮包

package zip;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class testZip {
public static void main(String[] args) {
ZipInputStream in = null;
try {
// Open the ZIP file
String inFilename = "E:\\aa.rar";
in = new ZipInputStream(new FileInputStream(inFilename));

// Get the first entry
ZipEntry entry = in.getNextEntry();

//next entry
while(entry != null){
System.err.println("文件名:"+entry.getName());
StringBuffer sb = new StringBuffer();
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) >0) {
sb.append(new String(buf, 0, len));
}
System.out.println(sb.toString());
entry = in.getNextEntry();
}

} catch (IOException e) {
}

finally{
if(in != null){
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

}
 

Java解壓gz壓縮包

package zip;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.zip.GZIPInputStream;

public class testGz {

public static void main(String[] args) {

try {

BufferedReader gzipReader = new BufferedReader(
new InputStreamReader(new GZIPInputStream(
new FileInputStream("E:\\aa.log.gz"))));
String line = gzipReader.readLine();
while (line != null) {
System.out.println(line);
line = gzipReader.readLine();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

}
 

 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved