Guest User

Untitled

a guest
Jul 18th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. public void unZipFiles(File zipFile,String descDir)throws IOException{
  2. File pathFile = new File(descDir);
  3. if(!pathFile.exists()){
  4. pathFile.mkdirs();
  5. }
  6. ZipFile zip = new ZipFile(zipFile);
  7. Enumeration<? extends ZipEntry> e = zip.entries();
  8. while(e.hasMoreElements()){
  9. ZipEntry entry = e.nextElement();
  10. String zipEntryName = entry.getName();
  11. InputStream in = zip.getInputStream(entry);
  12. String outPath = descDir+File.separator+zipEntryName;
  13. File file = new File(outPath);
  14. //判断文件全路径是否为文件夹,如果是创建文件夹,不需要解压
  15. if (zipEntryName.endsWith("\\") || zipEntryName.endsWith("/")){
  16. if(!file.exists()){
  17. file.mkdirs();
  18. }
  19. continue;
  20. }
  21. //输出文件路径信息
  22. OutputStream out = new FileOutputStream(file);
  23. byte[] buf = new byte[1024];
  24. int len;
  25. while((len=in.read(buf))>0){
  26. out.write(buf,0,len);
  27. }
  28. in.close();
  29. out.close();
  30. }
  31. System.out.println("******************解压完毕********************");
  32. }
Add Comment
Please, Sign In to add comment