刚刚做了个类似功能,与大家分享下,大家多提意见:
import java.io.*;
import java.util.zip.*;
import java.util.*;
public class UnZip {
static final int BUFFER = 2048; //设置缓冲流
public static String[] unZip(String path) {
String[] list = null;
String patht = new String(“文件路径”);
try {
BufferedOutputStream dest = null;
FileInputStream fis = new FileInputStream(path); //获得输入流
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
ZipEntry entry;
while ( (entry = zis.getNextEntry()) != null) {
int count;
byte data[] = new byte[BUFFER]; //开始读入
// 分文件写到磁盘
FileOutputStream fos = new FileOutputStream(patht+entry.getName());
dest = new BufferedOutputStream(fos, BUFFER);
while ( (count = zis.read(data, 0, BUFFER))
!= -1) {
dest.write(data, 0, count);
}
//关闭流
dest.flush();
dest.close();
}
zis.close();
File f = new File(patht);
list = f.list(); //返回由path指定路径里的所有文件名和目录名
}
catch (Exception e) {
e.printStackTrace();
}
return list;
}
}