Java解壓ZIP壓縮包
package zip;
imp
imp
imp
imp
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;
imp
imp
imp
imp
imp
imp
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();
}
}
}