M
Mark F
I'm trying to use this method for extracting Jar files. I already know it
works for Zip files just fine but it seems to bomb with Jar files. No
Exceptions are thrown it just exits with the following message:
Extracting Zip File: CreateRelations.jar
Extracting to: D:\CreateRelations
Extracting: D:\CreateRelations\META-INF\MANIFEST.MF
D:\CreateRelations\META-INF\MANIFEST.MF (The system cannot find the path
specified)
/**
* Extracts the compressed file to the directory given as location.
*
* @param location The location where the file should be extracted. The
* location does not need to already exist, it will be created if
necessary.
* @return boolean return value.
*/
public boolean extract(File location) {
InputStream in = null;
boolean extracted = false;
String entryName = "";
File entryPath = null;
try {
in = new BufferedInputStream(new FileInputStream(_file));
ZipInputStream zin = new ZipInputStream(in);
ZipEntry e;
while ( (e = zin.getNextEntry()) != null) {
entryPath = new File(location.toString() + File.separator +
e.getName());
if (e.isDirectory()) {
if (!FileOperation.directoryExists(entryPath)) {
System.out.println("Creating: " + entryPath);
FileOperation.mkdir(entryPath);
}
continue;
}
System.out.println("Extracting: " + entryPath.toString());
FileOutputStream out = new FileOutputStream(entryPath);
byte[] b = new byte[512];
int len = 0;
while ( (len = zin.read(b)) != -1) {
out.write(b, 0, len);
}
out.close();
}
extracted = true;
}
catch (FileNotFoundException ex) {
System.out.println(ex.getMessage());
}
catch (IOException io) {
System.out.println(io.getMessage());
}
return extracted;
}
works for Zip files just fine but it seems to bomb with Jar files. No
Exceptions are thrown it just exits with the following message:
Extracting Zip File: CreateRelations.jar
Extracting to: D:\CreateRelations
Extracting: D:\CreateRelations\META-INF\MANIFEST.MF
D:\CreateRelations\META-INF\MANIFEST.MF (The system cannot find the path
specified)
/**
* Extracts the compressed file to the directory given as location.
*
* @param location The location where the file should be extracted. The
* location does not need to already exist, it will be created if
necessary.
* @return boolean return value.
*/
public boolean extract(File location) {
InputStream in = null;
boolean extracted = false;
String entryName = "";
File entryPath = null;
try {
in = new BufferedInputStream(new FileInputStream(_file));
ZipInputStream zin = new ZipInputStream(in);
ZipEntry e;
while ( (e = zin.getNextEntry()) != null) {
entryPath = new File(location.toString() + File.separator +
e.getName());
if (e.isDirectory()) {
if (!FileOperation.directoryExists(entryPath)) {
System.out.println("Creating: " + entryPath);
FileOperation.mkdir(entryPath);
}
continue;
}
System.out.println("Extracting: " + entryPath.toString());
FileOutputStream out = new FileOutputStream(entryPath);
byte[] b = new byte[512];
int len = 0;
while ( (len = zin.read(b)) != -1) {
out.write(b, 0, len);
}
out.close();
}
extracted = true;
}
catch (FileNotFoundException ex) {
System.out.println(ex.getMessage());
}
catch (IOException io) {
System.out.println(io.getMessage());
}
return extracted;
}