• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Problem with searching for a file which is in the zip file

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
i m writing a program to search for a file(say .txt file).if the file is found it will write to a directory.

I m getting the problem with searching for a particular file(say txtfile) from the zip file.

this program work fine if i specify the zip file name and name of the file to be searched is given,bt i have many zip files in the folder and i want to search for a particular file in all zip files which are in the directory.

The arguments i m passing is:

java SearchZip <name-of the zip-file> <search-file> <destination-directory>

and my code is:

any suggestions?
Thannks in advance.a
[ November 28, 2005: Message edited by: Jim Yingst ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added [code] tags to your post so that we could see the indentation in the code. Please use these in the future whenever you post code, so that it's more easily readable. Also, some of your indentation seemed rather random, so I reformatted it for you. It's worthwhile to take the time to make your code look decent, as it increases the chance that people will want to look at it and maybe help you.

[Sanny kumar]: i want to search for a particular file in all zip files which are in the directory.

I would create a File object representing the directory, and use listFiles() to find all the files in that directory. Loop through them, and for each one with a name ending in .zip, open the zip file and search for the file you want (using the code you've already got).

Also, I would recommend breaking your code up into several smaller methods, rather than one long method. It's much more manageable to deal with it in small chunks.
[ November 28, 2005: Message edited by: Jim Yingst ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic