}
// 创建新文件
outFile.createNewFile();
// 如果不可写,则跳向下一个条目
if (!outFile.canWrite()) {
continue;
}
try {
// 获取读取条目的输入流
bin = new BufferedInputStream(zipFile.getInputStream(entry));
// 获取解压后文件的输出流
bout = new BufferedOutputStream(new FileOutputStream(outFile));
// 读取条目,并写入解压后文件
byte[] buffer = new byte[1024];
int readCount = -1;
while ((readCount = bin.read(buffer)) != -1) {
bout.write(buffer, 0, readCount);
}
} finally {
try {
bin.close();
bout.flush();
bout.close();
} catch (Exception e) {}
}
}
}
public static void main(String[] args) throws Exception{
//compressTest2();
//decompressTest();
}
public static void compressTest() throws Exception {
String sourcePath = "E:" + File.separator + "文档" + File.separator + "音乐";
String zipPath = "E:" + File.separator + "我的音乐.zip";
String comment = "音乐压缩文件";
compress(sourcePath, zipPath, "GBK", comment);
}
public static void decompressTest() throws Exception {
String zipPath = "E:" + File.separator + "我的音乐.zip";
String targetPath = "E:" + File.separator + "temp";
decompress(zipPath, targetPath, "GBK");
}
public static void compressTest2() throws Exception {
List
list.add("E:" + File.separator + "文档" + File.separator + "音乐");
list.add("E:" + File.separator + "文档" + File.separator + "视频");
list.add("E:" + File.separator + "文档" + File.separator + "资料");
list.add("E:" + File.separator + "文档" + File.separator + "书籍");
String zipPath = "E:" + File.separator + "我的文档压缩文件.zip";
String comment = "我的文档压缩文件";
compress(list, zipPath, "GBK", comment);
}
}