Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8117787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:17:16+00:00 2026-06-06T04:17:16+00:00

I am trying to find a file within a zip file and get it

  • 0

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…

public InputStream Search_Image(String file_located, ZipInputStream zip) 
    throws IOException {
    for (ZipEntry zip_e = zip.getNextEntry(); zip_e != null ; zip_e = zip.getNextEntry()) {
        if (file_located.equals(zip_e.getName())) {
            return zip;
        }
        if (zip_e.isDirectory()) {
            Search_Image(file_located, zip); 
        }
    }
    return null;
}

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

if(zip_e.isDirectory()) {
    //"zip" is the same as the original I need a change here to find folders again.
    Search_Image(file_located, zip); 
}

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:17:18+00:00Added an answer on June 6, 2026 at 4:17 am

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

    ZipFile file = new ZipFile("file.zip");
    ZipInputStream zis = searchImage("foo.png", file);
    
    public InputStream searchImage(String name, ZipFile file) {
      for (ZipEntry e : Collections.list(file.entries())) {
        if (e.getName().endsWith(name)) {
          return file.getInputStream(e);
        }
      }
      return null;
    }
    

    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
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What does mean? I get this error when trying to iterate through a file
I'm trying to find a file using BFS and recursion , where given a
I'm trying to find a way to find out what file and line number
I am trying to find keywords from a text file, when the keywords are
I'm trying to find and read a string from a text file using a
I am trying to find and replace a couple of words in a file
I've been trying to find a way to write to a file when using
I'm trying to find a way to write to a text file from as2.
I have been trying to find a way of getting a windows batch file
I'm trying to find a way to save a video file. Initially I'd put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.