Skip to content

Instantly share code, notes, and snippets.

@zxlooong
Last active December 18, 2015 12:59
Show Gist options
  • Save zxlooong/5786708 to your computer and use it in GitHub Desktop.
Save zxlooong/5786708 to your computer and use it in GitHub Desktop.
readInnerZipFile.java
public static boolean readInnerZipFile(String oriZipFile,String
innerZipFileEntryName, String outZipFileEntryName) {
ZipFile innerZipFile = null;
try {
innerZipFile = new ZipFile(oriZipFile);
Enumeration entries = innerZipFile.entries();
ZipEntry entryIn = null;
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
// System.out.println(entry);
if (entry.getName().compareToIgnoreCase(innerZipFileEntryName) == 0) {
entryIn = entry;
break;
}
}
if (entryIn != null) {
InputStream In = innerZipFile.getInputStream(entryIn);
OutputStream ow = new FileOutputStream(outZipFileEntryName,true);
byte[] b = new byte[256];
int len = In.read(b);
while (len > 0) {
ow.write(b, 0, len);
len = In.read(b);
}
ow.flush();
ow.close();
In.close();
return true;
} else {
return false;
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment