Hi all friends,
I want to delete that .zip file which I have unziped progrmatically with my below codes.With my below codes I couldn't delete that .zip file after unzip.Can any one plz
test my below codes where Iam wrong.Eagerly waiting for someone reply.
import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.zip.*;
import javax.swing.*;
public class Unzipper {
public static ProgressMonitor monitor;
public static Final file;
public Unzipper() {}
public static byte[] buffer = new byte[16384];
public static void unzip(File file, Component parentComponent, File outputDir) throws ZipException, IOException {
unzip(new ZipFile(file), parentComponent, outputDir);
}
public static void unzip(File file, int mode, Component parentComponent, File outputDir) throws IOException {
unzip(new ZipFile(file, mode), parentComponent, outputDir);
}
public static void unzip(
String name, Component parentComponent, File outputDir) throws IOException {
unzip(new ZipFile(name), parentComponent, outputDir);
}
public static void unzip(ZipFile zip, Component parentComponent, File outputDir) throws IOException {
if ( zip == null) {
throw new NullPointerException("outputDir is null");
}
int size = zip.size();
if (size > 0) {
if (outputDir == null) {
throw new NullPointerException("outputDir is null");
}
if (!outputDir.exists()) {
outputDir.mkdirs();
}
monitor = new ProgressMonitor(parentComponent,"Unpacking " + zip.getName() + "...", "", 0, size);
monitor.setMillisToDecideToPopup(0);
monitor.setMillisToPopup(0);
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());
file.getParentFile().mkdirs();
if (!entry.isDirectory()) {
InputStream in = null;
OutputStream out = null;
try {
in = zip.getInputStream(entry);
out = new FileOutputStream(file);
for (int n=0; (n = in.read(buffer)) >= 0; )
out.write(buffer, 0, n);
monitor.setProgress(++i);
out.flush();
out.close();
in.close();
}catch(IOException ioex){
ioex.printStackTrace();
}
}
}
}
}
public static void main(String[] args) throws ZipException, IOException
{
if (args.length !=2) {
System.err.println("Usage:
java Unzipper <zip file> <output dir>");
System.exit(1);
}
long start = -System.currentTimeMillis();
unzip(args[0], null, new File(args[1]));
monitor.close();
file.delete();
System.out.println(start+System.currentTimeMillis());
}
}
Regards
Bikash

[ July 10, 2003: Message edited by: Bikash Paul ]