aspose file tools*
The moose likes I/O and Streams and the fly likes Problem with searching for a file which is in the zip file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Problem with searching for a file which is in the zip file" Watch "Problem with searching for a file which is in the zip file" New topic
Author

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

Sanny kumar
Ranch Hand

Joined: May 18, 2005
Posts: 53
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

Joined: Jan 30, 2000
Posts: 18671
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 ]

"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with searching for a file which is in the zip file
 
Similar Threads
How to unzip a zip file which contains another zip file?
Problem in unzipping the zip file
How to extract subdirectories with java.util.zip
Exception in thread "main" java.io.FileNotFoundException: ReadZip (Access is denied)
Java --- ZIP & UNZIP