📄 gsunjar.java
字号:
package jp.co.sjts.gsession.tools.archive;
import java.io.File;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
public class GSUnJar {
public String fname = null;
public String pathname = null;
public GSUnJar(String fname,String pathname) {
this.fname = fname;
this.pathname = pathname;
}
public GSUnJar(File file,File path) {
this.fname = file.getPath();
this.pathname = path.getPath();
}
public void write() {
try {
byte[] buf = new byte[1024*8];
FileInputStream fi = new FileInputStream(fname);
JarInputStream in = new JarInputStream(new BufferedInputStream(fi));
JarEntry je;
ByteArrayOutputStream bao = new ByteArrayOutputStream();
while((je = in.getNextJarEntry()) != null) {
bao.reset();
File file = new File(pathname + je.getName());
if(file.isDirectory()) {
makeDirs(file);
}
else {
File file2 = new File(file.getParent() + File.separator);
if( !file2.exists() ) {
makeDirs(file2);
}
// int result;
// do {
// result = in.read(buf,0,buf.length);
// if(result != -1)
// bao.write(buf,0,result);
// }while (result == buf.length);
int r;
while((r = in.read()) != -1) {
Integer b = new Integer(r);
bao.write(b.byteValue());
}
byte[] data = bao.toByteArray();
FileOutputStream fo = new FileOutputStream(pathname + je.getName());
BufferedOutputStream bos = new BufferedOutputStream(fo);
fo.write(data);
fo.close();
}
}
in.close();
}
catch(Exception e) {
System.err.println(e);
}
}
private void makeDirs(File dir) {
File file = null;
file = dir;
int index = 0;
String name = file.getPath() + File.separator;
File file2 = null;
for(int i=0;i<name.lastIndexOf(File.separator);i=index) {
index = name.indexOf(File.separator,index) + 1;
// File file2 = new File(name.substring(0,index));
file2 = new File(name.substring(0,index));
if(!file2.exists())
file2.mkdir();
}
System.out.println("mkDirs end");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -