Hi i am tryign to unjar a file the input to the contructors will be the jar file name and the path (directory ) in which the jar file has to be extracted .. iu am trying this but doesnt seems to work can anybody help me i trying to call this class from other class
thanks
/**
* <p>Title: REMOVE THIS LINE</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003-2004</p>
* <p>Company: Advantage Business Computer Systems, Inc.</p>
* @author not attributable
* @version 1.0
*/
import java.io.*;
import java.util.*;
import java.util.jar.*;
import java.io.*;
import java.util.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import com.abcsinc.database.dataset.*;
import com.abcsinc.database.schema.*;
import com.abcsinc.util.*;
public class UnJar {
public UnJar() {
}
static final int BUFFER = 2048;
public UnJar(
String jarFile, String destDir) {
try {
BufferedOutputStream dest = null;
BufferedInputStream is = null;
JarEntry entry;
System.out.println("Enetered UnJar.java :the jarfile " + jarFile );
JarFile jarfile = new JarFile(jarFile);
Enumeration e = jarfile.entries();
while(e.hasMoreElements()) { //going through each entries one by one
System.out.println("UnJar.java :the path of dest dir " + destDir );
entry = (JarEntry) e.nextElement();
System.out.println("Extracting: " + entry);
is = new BufferedInputStream
(jarfile.getInputStream(entry));
int count;
File destdir = new File(destDir);
destdir.mkdir();
byte data[] = new byte[BUFFER];
System.out.println("entry.getname "+entry.getName());
//FileOutputStream fos = new FileOutputStream(entry.getName());
File destfilename = new File(destdir,entry.getName());
String destfilepath = destfilename.getAbsolutePath();
System.out.println("the name of the destination file name " + destfilepath);
FileOutputStream fos = new FileOutputStream(destfilename);
dest = new
BufferedOutputStream(fos, BUFFER);
while ((count = is.read(data, 0, BUFFER))!= -1) {
dest.write(data, 0, count);
}
dest.flush();
dest.close();
is.close();
}
} catch(Exception e) {
e.printStackTrace();
}
}
// }//main ends
}//class ends