Guest User

Untitled

a guest
Oct 1st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. public static void lookupSomethingInZip(InputStream is) throws IOException {
  2.         ZipInputStream zipInputStream = new ZipInputStream(is);
  3.         String entryName = "";
  4.         ZipEntry entry = zipInputStream.getNextEntry();
  5.  
  6.         while (entry!=null) {
  7.             entryName = entry.getName();
  8.             if (entryName.endsWith("zip")) {
  9.                 //recur if the entry is a zip file
  10.                 lookupSomethingInZip(zipInputStream);
  11.             }
  12.  
  13.             if (entryName.endsWith("txt")) {
  14.                 String str =
  15.                         new BufferedReader(new InputStreamReader(zipInputStream))
  16.                                 .lines().collect(Collectors.joining("\n"));
  17.                 System.out.println(str);
  18.                 // if we need only first file
  19.                 break;
  20.             }
  21.             //do other operation with the entries..
  22.  
  23.             entry = zipInputStream.getNextEntry();
  24.         }
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment