public void unzip(InputStream inputStream){
try {
String outputDirectory = "data/data/cn.appname.app/";
ZipInputStream zin = new ZipInputStream(inputStream);
ZipEntry z = zin.getNextEntry();
while (z != null) {
File f;
if(z.getName().length()>8){
if (z.isDirectory()) {
String name =z.getName();
name = name.substring(8,name.length() - 1);
String filePath =outputDirectory+name;
f = new File(filePath);
if(!f.exists()){
f.mkdirs();
}
}
else{
String path =outputDirectory + z.getName().substring(8);
//System.out.println(path);
f = new File(path);
f.createNewFile();
FileOutputStream out = new FileOutputStream(f);
byte[] buf = new byte[1024];
int len = 0;
while((len=zin.read(buf))>0){
out.write(buf,0,len);
}
out.close();
}
}
z = zin.getNextEntry();
}
zin.close();
} catch (FileNotFoundException e) {
// TODO: handle exception
e.printStackTrace();
}catch (IOException e) {
// TODO: handle exception
e.printStackTrace();
}
}
zip文件解压
最新推荐文章于 2024-05-10 09:46:44 发布