472,960 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,960 software developers and data experts.

Problem in Unzipping the zip files


I have created a program to unzip the file. It is unzipping the zip files when put in directory i.e folder inside folder but when i create a zip file without putting in a folder and try to unzip it. It unzips it but put the zipped file outside the folder created in the name of the zip file. I want it to be inside it.

Also when i do beyond compare of the two files i.e the zipped file and original file its shows difference.

What should i do

I have pasted the code below:

//Unzip the zip files to the folder with their name

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

// Getting the path to find the type of files
public class zipper implements FilenameFilter{
String ext;

public zipper(String ext)
this.ext="." + ext;

public boolean accept(File dir,String name)
return name.endsWith(ext);

public static void main(String args[]) throws IOException
String dir = "D:/";

File f2 = new File(dir);

FilenameFilter fn= new zipper("zip");
String ss[]=f2.list(fn);

for ( int j = 0; j < ss.length; j++)
System.out.println(" Extracting ...." + ss[j]) ;
String zipFile = dir + ss[j];

ZipFile zf = new ZipFile(zipFile);
Enumeration entries = zf.entries();

String directoryName = zf.getName();
directoryName = directoryName.substring(0, (directoryName.indexOf(":" + File.separator) + 2));

String folderName = zf.getName();
folderName = folderName.substring(0, folderName.lastIndexOf("."));
File file1 = new File(folderName);

while (entries.hasMoreElements())
ZipEntry ze = (ZipEntry) entries.nextElement();
String path = directoryName + ze.getName() ;

//System.out.println(" : " + path);
if (ze.getName().endsWith("/"))
File file = new File(path);

BufferedReader bReader = new BufferedReader(new InputStreamReader(zf.getInputStream(ze)));
StringBuffer fileBuffer = new StringBuffer(" ");
String line ;

while ((line = bReader.readLine()) != null)
//line = line + "\r\n";
//byte[] b = new byte[line.length()];
//b =line.getBytes();


String fileData = fileBuffer.toString();
File f1 = new File(path);
FileOutputStream out = new FileOutputStream(path);
//FileOutputStream out = new FileOutputStream(new File(folderName + "/" + ze.getName()));
long size = ze.getSize();

byte[] data1 = new byte[fileData.length()];

for (int i = 0; i < fileData.length(); i++)
data1[i] = (byte) fileData.charAt(i);
catch (Exception e)


Thanks in Advance

Sep 11 '07 #1
0 2010

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Terry | last post by:
I have created a switchboard, created using Access 2000. If I put the mouse anywhere on the form, outside of the checkboxes and scroll the wheel backwards, I get the following error. Run-Time...
by: Owen Jenkins | last post by:
I've been using Dev's fantastic InetTransferLib to upload and download files via ftp. Now I'm using the http procedures to have my application download zip files from my website. Although the...
by: Owen Jenkins | last post by:
Reposting this message from last week since I have not had a reply so far. Hopefully someone will have an idea? --- I've been using Dev's fantastic InetTransferLib to upload and download files...
by: thewhoracle | last post by:
I have a C# application that essentially builds batch and text files and runs them from the command line, but i need to unzip something from the command line. What i need is either an unzipping...
by: batista | last post by:
Hi there, i have a web service which is using a dll written in vc7.This dll in turn is accessing a vc6 com dll through interop. Now the problem is that i have a function in vc6 that takes as...
by: stjulian | last post by:
On Windows Server 2003, IIS 6 I am looking for an unzipping component. I have a series of files that are available zipped at a considerable decrease in size. And before ASPINET fails on a script...
by: kss | last post by:
Hey all, I am new to python and I need to unzip a zip file which is password protected. I tried using zipfile class. Aparently, when i try doing a zip.read(filename), it throws an exception stating...
by: Neil Crighton | last post by:
I'm using the zipfile library to read a zip file in Windows, and it seems to be adding too many newlines to extracted files. I've found that for extracted text-encoded files, removing all instances...
by: deepakd | last post by:
Hi I'm using wxZipInputStream for unzipping a zipped ".app" file in MAC OS.After unzipping i am not able to run the app.When i manually copy the unix executable to app packages, I am able to run...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.