通过对数据压缩算法的简要介绍,利用java.util.zip包实现数据的压缩与解压,并扩展到在网络传输方面如何应用java.util.zip包现数据压缩与解压。供广大java爱好者以及开发者学习使用,节约了开发者时间,是当前比较流行的压缩代码。
部分代码介绍:
/**
* 功能:把 sourceDir 目录下的所有文件进行 zip 格式的压缩,保存为指定 zip 文件
* @param sourceDir 如果是目录,eg:D:\\MyEclipse\\first\\testFile,则压缩目录下所有文件;
* 如果是文件,eg:D:\\MyEclipse\\first\\testFile\\aa.zip,则只压缩本文件
* @param zipFile 最后压缩的文件路径和名称,eg:D:\\MyEclipse\\first\\testFile\\aa.zip
*/
public File doZip(String sourceDir, String zipFilePath)
throws IOException {
File file = new File(sourceDir);
File zipFile = new File(zipFilePath);
ZipOutputStream zos = null;
try {
// 创建写出流操作
OutputStream os = new FileOutputStream(zipFile);
BufferedOutputStream bos = new BufferedOutputStream(os);
zos = new ZipOutputStream(bos);
String basePath = null;
// 获取目录
if(file.isDirectory()) {
basePath = file.getPath();
}else {
basePath = file.getParent();
}
















大小: 109KB
大小: 131M
PHP和MySQL Web开发第4版源代码
SSH框架整合小案例
51单片机150个例程
PHP操作excel类(PHPExcel)1.7.7
逐梦旅程:Windows游戏编程之从零开始 配套源代码
HTML 5开发精要与实例详解 配套源码
HTML-CSS-JavaScript标准教程实例版
c语言经典编程900例
C# 教务管理系统源码
C++Builder学习大全中文版