请教一下各位,我现在已经可以人一个指定地点的.jar文件里解出指定的单个文件,代码如下:
public static void extract(String dest){
try {
String home = "/Applications/backup/try/a.jar";
JarFile jar = new JarFile(home);
ZipEntry entry = jar.getEntry("sandbox.jar");
File efile = new File(dest, entry.getName()); InputStream in =
new BufferedInputStream(jar.getInputStream(entry));
OutputStream out =
new BufferedOutputStream(new FileOutputStream(efile));
byte[] buffer = new byte[2048];
for (;;) {
int nBytes = in.read(buffer);
if (nBytes <= 0) break;
out.write(buffer, 0, nBytes);
}
out.flush();
out.close();
in.close();
Runtime.getRuntime().exec("cd /Applications/backup/try/");
Runtime.getRuntime().exec("jar xf sandbox.jar");
}
catch (Exception e) {
e.printStackTrace();
}
}但是这个只能解出单个的文件,请教各位dx如何将一整个文件夹全部解出来呢,需要保留完整子结构。
谢谢各位!
public static void extract(String dest){
try {
String home = "/Applications/backup/try/a.jar";
JarFile jar = new JarFile(home);
ZipEntry entry = jar.getEntry("sandbox.jar");
File efile = new File(dest, entry.getName()); InputStream in =
new BufferedInputStream(jar.getInputStream(entry));
OutputStream out =
new BufferedOutputStream(new FileOutputStream(efile));
byte[] buffer = new byte[2048];
for (;;) {
int nBytes = in.read(buffer);
if (nBytes <= 0) break;
out.write(buffer, 0, nBytes);
}
out.flush();
out.close();
in.close();
Runtime.getRuntime().exec("cd /Applications/backup/try/");
Runtime.getRuntime().exec("jar xf sandbox.jar");
}
catch (Exception e) {
e.printStackTrace();
}
}但是这个只能解出单个的文件,请教各位dx如何将一整个文件夹全部解出来呢,需要保留完整子结构。
谢谢各位!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货