老师要一个代码...不能太短滴!
谢谢啦
老师要一个代码...不能太短滴!
谢谢啦
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import org.apache.tools.ant.taskdefs.Replace;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;
import org.apache.tools.zip.ZipOutputStream;
public class Decompression {
public void unZip(String zipfile, String destDir) {
destDir = destDir.endsWith("\\") ? destDir : destDir + "\\";
byte b[] = new byte[1024];
int length;
OutputStream outputStream = null;
InputStream inputStream = null;
ZipFile zipFile = null;
try {
File f = new File(zipfile);
zipFile = new ZipFile(f);
Enumeration enumeration = zipFile.getEntries();
ZipEntry zipEntry = null;
while (enumeration.hasMoreElements()) {
zipEntry = (ZipEntry) enumeration.nextElement();
File loadFile = new File(destDir + zipEntry.getName());
if (zipEntry.isDirectory()) {
loadFile.mkdirs();
} else {
if (!loadFile.getParentFile().exists())
loadFile.getParentFile().mkdirs();
outputStream = new FileOutputStream(loadFile);
inputStream = zipFile.getInputStream(zipEntry);
while ((length = inputStream.read(b)) > 0)
outputStream.write(b, 0, length);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
zipFile.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (null != outputStream) {
try {
outputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (null != inputStream) {
try {
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
解压ZIP文件 需要引入架包的
多写几个实体类。。搭好框架。。就差不多了。。