This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Unzip  RSS feed

 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..
I have a zip file which comes from DB as a blob and I need to check the contents of the files after unzipping.The checks I need to make are..
1) The zip file should not contain more than one file in it
2)The file inside the zip file should be in a particular extension( like .xml or xls).
Am using servlets to get the data from the DB perform all these operations.
Any inputs as to how to procees will be helpful
Thx
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mary,
It seems to me that you have the Servlet part already figured out. So I think I will move this to the IO and Streams forum so those experts can handle your specific needs regarding Zipped files, extensions, etc.
 
Sri Basavanahally
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Mary !
the following shows how to unzip the a zip file, get the file names etc. It will help you.the classes you need are in java.util.zip.*;
when you get the zip file from the DB,create a zip file as follows:
ZipFile zipfile = new Zipfile(filename);
then: get the entries in the zip file:
Enumeration entries = zipfile.entries();
then you can go through all of them
while(entries.hasMoreElements())
{
//get the entry
ZipEntry entry = (ZipEntry)entries.nextElement();
//get file name
String name = entry.getName();

//parse the name
if(name.substring(..)){}
//OR
StringTokenizer st = new StringTokenizer(name,".");
----- so on-----
}//end while
Hope that helps

-Sri
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!