public class linzip { public static String make8859toGB(String str) { try{ String str8859 = new String(str.getBytes("8859_1"),"GB2312"); return str8859; }catch(UnsupportedEncodingException ioe){ return str; } }
public static void main(String[] args) { if (args.length < 1){ System.err.PRintln("Required parameter missing!"); System.exit(-1); }
File infile = new File(args[0]);
try{ //检查是否是ZIP文件 ZipFile zip = new ZipFile(infile); zip.close();
//建立与目标文件的输入连接 ZipInputStream in = new ZipInputStream(new FileInputStream(infile)); ZipEntry file = in.getNextEntry();
int i =infile.getAbsolutePath().lastIndexOf('.'); String dirname = new String(); if ( i != -1 ) dirname = infile.getAbsolutePath().substring(0,i); else dirname = infile.getAbsolutePath(); File newdir = new File(dirname); newdir.mkdir();
byte[] c = new byte[1024]; int len; int slen;
while (file != null){
i = make8859toGB(file.getName()).replace('/','//').lastIndexOf('//'); if ( i != -1 ){ File dirs = new File(dirname+File.separator+make8859toGB(file.getName()).replace('/','//').substring(0,i)); dirs.mkdirs(); dirs = null; }