[Advanced-java] After Unzip delete that file programatically??
Nikolaos Giannopoulos
nikolaos at solmar.ca
Thu Jul 10 17:35:41 2003
Your program makes little sense:
Q. What do you think file (which is for some odd reason a static) will
retain if it is changed with every iteration of this loop?
A. The last file object that was created!
<snip>
> Enumeration entries = zip.entries();
> for ( int i = 0; entries.hasMoreElements(); ) {
> ZipEntry entry = (ZipEntry) entries.nextElement();
> monitor.setNote(entry.getName());
> file = new File(outputDir, entry.getName());
<snip>
> }
Q. What do you think your going to delete here?
A. At best if your program works - the last unzipped file ONLY and NOT the
zipped file itself as the file object that refers to it is long gone.
> file.delete();
If you want to write a utilities type class then don't retain static
attributes and simply call a single method that does what you want i.e.
hint: your unzip method signature could look like this:
public static void unzip(
String rootDir, File zipFile, boolean deleteZipOnExit)
--Nikolaos