import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
public class Test {
public static void main(String[] args) throws Exception {
try {
//读文件的路径
readZipFile("D:\\tupian.zip");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void readZipFile(String file) throws Exception {
ZipFile zf = new ZipFile(file);
InputStream in = new BufferedInputStream(new FileInputStream(file));
ZipInputStream zin = new ZipInputStream(in);
ZipEntry ze;
while ((ze = zin.getNextEntry()) != null) {
if (ze.isDirectory()) {
} else {
System.err.println("file - " + ze.getName() + " : "+ ze.getSize() + " bytes");
InputStream inputStream = zf.getInputStream(ze);
byte[] bytes=new byte[1024];
int len;
FileOutputStream fileOutputStream=null;
try{
//写入的路径
fileOutputStream=new FileOutputStream("C:\\zwork\\"+ze.getName());
while((len=inputStream.read(bytes))!=-1){
fileOutputStream.write(bytes,0,len);
}
}catch (Exception e){
e.printStackTrace();
}finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
zin.closeEntry();
}
}
共同学习,写下你的评论
评论加载中...
作者其他优质文章