Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Sanny kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • 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 ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic