title: Error on Extracting a File in zip archive in Java
body: <p>I'm extracting a file from a zip archive using this code (omitting all the catch statements and other initialization statements):</p>
  
  <pre><code>zipInputStream = new ZipInputStream(new FileInputStream(file));
  zipFile = new ZipFile(file);
  for (Enumeration&lt;?&gt; em = zipFile.entries(); em.hasMoreElements();) {
      String extractedFileName = em.nextElement().toString();
      ZipEntry outerZipEntry = zipInputStream.getNextEntry();
      if (outerZipEntry.getName().contains(searchString)) {
          extractedFile = new File(outputDir + outerZipEntry.getName());
          out = new FileOutputStream(outputDir + extractedFileName);
          byte[] buf = new byte[1024];
          int len;
          while ((len = zipInputStream.read(buf)) &gt; 0) {
              out.write(buf, 0, len);
          }
          break;
       } 
  }
  </code></pre>
  
  <p>This code works fine when extracting a file in say, /archive.zip/file_i_need.txt.</p>
  
  <p>But when I'm trying to extract a file from /archive.zip/folder1/file_i_need.txt, I get an exception java.lang.NullPointerException when I try to use readLine() to read the file in:</p>
  
  <pre><code>String line = null ;
  BufferedReader input = new BufferedReader(newFileReader(extractedFile)) ;
  while( (line = input.readLine() ) != null ) {
      ...
  }
  </code></pre>
  
  <p>I've tested it on both cases and it seems like this code will not work when the file is inside a folder because the extractedFileName is 'folder/file_i_need.txt' compared to just 'file_i_need.txt'. </p>
  
  <p>Any suggestions you can recommend?</p>
  
  <p>Thanks!</p>