Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void unZipFiles(File zipFile,String descDir)throws IOException{
- File pathFile = new File(descDir);
- if(!pathFile.exists()){
- pathFile.mkdirs();
- }
- ZipFile zip = new ZipFile(zipFile);
- Enumeration<? extends ZipEntry> e = zip.entries();
- while(e.hasMoreElements()){
- ZipEntry entry = e.nextElement();
- String zipEntryName = entry.getName();
- InputStream in = zip.getInputStream(entry);
- String outPath = descDir+File.separator+zipEntryName;
- File file = new File(outPath);
- //判断文件全路径是否为文件夹,如果是创建文件夹,不需要解压
- if (zipEntryName.endsWith("\\") || zipEntryName.endsWith("/")){
- if(!file.exists()){
- file.mkdirs();
- }
- continue;
- }
- //输出文件路径信息
- OutputStream out = new FileOutputStream(file);
- byte[] buf = new byte[1024];
- int len;
- while((len=in.read(buf))>0){
- out.write(buf,0,len);
- }
- in.close();
- out.close();
- }
- System.out.println("******************解压完毕********************");
- }
Add Comment
Please, Sign In to add comment