freesoft_2000 9 Practically a Master Poster

Hi everyone,
I have a weird problem. I have created a zip manager and
unzip manager. The zip manager works alright in a sense that it can create
zip files and also the contents of the zip file zipped by my own zip manager
can be extracted by using winzip.

The next program is as i have explained is the unzip manager that i have created can unzip any zip files except the zip files created using my zip manager. My unzip manager can list the contents of the zip file created with my zip manager in the list box but is unable to extract the contents of the zip file created by my zip manager.

I really don't understand why this is so. I am using the java 1.4.2 sdk
Here is the listing of my code maybe someone can e-mail me or tell me what i am doing wrong or is this a bug in Java

Someone please explain this weirdness to me

Here is the main function that does the extraction of files. The graphical interfaces have all already been declared above together with the JFileChooser. I will also list the function that lists the content of the zip file
for clarity sake.

Here is the function to list the archive's content

public void listarchivecontent ()
{

String name, str;
FileChooser1.setDialogType(JFileChooser.OPEN_DIALOG);
FileChooser1.setDialogTitle("Open Archive");
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm a");

List1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
List1.setLayoutOrientation(JList.VERTICAL);

if(FileChooser1.showDialog(fr, "Extract") != JFileChooser.APPROVE_OPTION)
{

}

File f = FileChooser1.getSelectedFile();
name = f.getName().toLowerCase();

try
{

ZipFile zipfile = new ZipFile(f.getPath());
Enumeration en = zipfile.entries();

while(en.hasMoreElements())
{
ZipEntry zipentry = (ZipEntry)en.nextElement();
Date d = new Date(zipentry.getTime());
str = zipentry.getName() + "   " + zipentry.getSize() + "   " + sdf.format(d);
list.addElement(str);
}

zipfile.close();
}

catch(Exception e)
{
Label1.setText("An extraction error has occured");
}

}

Here is the function that extracts the data

public void extractarchive ()
{
String s;
byte [] buffer1 = new byte[1024];
int len = 0;

FileChooser2.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);  
FileChooser2.setDialogType(JFileChooser.OPEN_DIALOG);
FileChooser2.setDialogTitle("Select output directory");

if(FileChooser2.showDialog(fr, "Directory") != JFileChooser.APPROVE_OPTION)
{

}

File archive = FileChooser1.getSelectedFile();
File destination = FileChooser2.getCurrentDirectory();

try
{
InputStream in = new BufferedInputStream(new FileInputStream(archive));    
ZipInputStream zin = new ZipInputStream(in);
ZipEntry e;

while((e=zin.getNextEntry())!= null)
{     
s = e.getName();           
File f = new File(destination , s);
FileOutputStream out = new FileOutputStream(f);
while ((len = zin.read(buffer1)) != -1 ) 
{
out.write(buffer1,0,len);
}
out.close();                                    
}
zin.close();
}

catch(IOException e)
{
Label1.setText("A file extraction error has occured");
}

}

I sincerely apologize for the length of this program

I hope someone can really help me.

My e-mail is freesoft_2000@yahoo.com

Thank You for your patience

Yours Sincerely

Richard West

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.