Java Zip????????
???????????? ???????[ 2014/10/8 11:09:36 ] ????????Java ????
???????????zip?????????????????????衢???????code??
???????????????????????????????????????????????й?ɡ?
???????????Ubuntu14.04??eclipse ?????STS3.5??jdk81.8.0_20
????????????????????????????code??????????????????????????????????????
????????????maven??????????jar????????
????<!-- ????zip???????? -->
????<dependency>
????<groupId>ant</groupId>
????<artifactId>ant</artifactId>
????<version>1.7.0</version>
????</dependency>
???????????£?
package com.uujava.mbfy.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.tools.zip.ZipOutputStream;
/**
* @author k
* @date 2014??10??7?? ????8:04:51
* @Description: TODO(?????????????zip???)
* ??????bug:
* ?????????????????????????а????????????ж???????????????
*/
public final class ZipUtils {
public static void main(String[] args) throws Exception {
// ZipFile("/home/k/Documents/testzip/???????html5?????.zip"?? "/home/k/Documents/testzip/index.html");
unZipFile("/home/k/Documents/testzip/???????html5?????.zip"??
"/home/k/Documents/testzip/zip");
}
public static void zip(ZipOutputStream out?? File f?? String base??
boolean first) throws Exception {
if (first) {
if (f.isDirectory()) {
out.putNextEntry(new org.apache.tools.zip.ZipEntry("/"));
base = base + f.getName();
first = false;
} else
base = f.getName();
}
if (f.isDirectory()) {
File[] fl = f.listFiles();
base = base + "/";
for (int i = 0; i < fl.length; i++) {
zip(out?? fl[i]?? base + fl[i].getName()?? first);
}
} else {
out.putNextEntry(new org.apache.tools.zip.ZipEntry(base));
FileInputStream in = new FileInputStream(f);
int b;
System.out.println(base);
while ((b = in.read()) != -1) {
out.write(b);
}
in.close();
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11