Extracting Zip/Jar Files Different?

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;

}
 
L

Liz

Mark F said:
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)

It appears that it requires a manifest file to exist in the jar file, so
just put one and try again.
/**
* 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;

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top