Skip to content
Advertisement

Finding a file in zipentry java

I am trying to find a file within a zip file and get it as an InputStream. So this is what I am doing to get it so far and I am not certain if I am doing it correctly.

Here is a sample as the original is slightly longer but this is the main component…

JavaScript

Now the main problem I am facing is that The ZipInputStream in Search_Image is the same as the original component of the ZipInputStream

JavaScript

Now for the question, how do you get the ZipInputStream as the new zip_entry? Also please add in if I did anything wrong in my method as my logic with this class is still lacking.

Advertisement

Answer

You should use the class ZipFile without worrying yourself with an input stream if you don’t need it yet.

JavaScript

Some facts:

  • you should follow conventions for naming methods and variables in your code (Search_Image is not fine, searchImage is)
  • directories in zip files does not contain any file, they are just entries like everything else so you shouldn’t try to recurse into them)
  • you should compare the name you provide by using endsWith(name) because the file could be inside a folder and a filename inside a zip always contains the path
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement