解压缩工具类
来源:互联网 发布:mysql没有可视化界面 编辑:程序博客网 时间:2024/06/02 04:41
/**
* 解压缩工具类
* @author Administrator
*
*/
public class GzipUtil {
// 压缩文件
public static void zip(File srcFile, File targetFile) {
InputStream is = null;
GZIPOutputStream gos = null;
try {
is = new FileInputStream(srcFile);
gos = new GZIPOutputStream(new FileOutputStream(targetFile));
byte buff[] = new byte[1024];
int len = 0;
while ((len = is.read(buff)) != -1) {
gos.write(buff, 0, len);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
CloseQuitely(is);
CloseQuitely(gos);
}
}
/**
* 解压缩
* @param srcFile 源文件 压缩文件
* @param targetFile 目标文件 普通文件
*/
public static void unZip(File srcFile, File targetFile) {
GZIPInputStream gis = null;
OutputStream out = null;
try {
gis = new GZIPInputStream(new FileInputStream(srcFile));
out = new FileOutputStream(targetFile);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = gis.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
CloseQuitely(gis);
CloseQuitely(out);
}
}
/**
* 关闭流
*/
public static void CloseQuitely(Closeable stream) {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* 解压缩
* @param in 输入流 压缩包
* @param targetFile 目标文件 普通文件
*/
public static void unZip(InputStream in,File targetFile){
GZIPInputStream gis=null;
FileOutputStream fos=null;
try {
gis=new GZIPInputStream(in);
fos=new FileOutputStream(targetFile);
byte []buffer=new byte[1024];
int len=0;
while((len=gis.read(buffer))!=-1){
fos.write(buffer, 0,len);
}
} catch (Exception e) {
// TODO: handle exception
}finally{
CloseQuitely(gis);
CloseQuitely(fos);
}
}
}
0 0
- 解压缩工具类
- java 解压缩工具类
- java解压缩工具类
- 解压缩工具类
- java 压缩&解压缩 工具类
- GZip压缩解压缩工具类
- java解压缩文件工具类
- Android Zip解压缩工具类
- Java实现的ZIP解压缩工具类
- Java压缩、解压缩工具类(Ant)
- ziputils java压缩/解压缩工具类
- gzip工具类 支持字符串压缩解压缩
- 工具(四):Java压缩解压缩工具类
- 解压缩SIS文件工具
- Ubuntu 解压缩工具安装
- Android_Zip解压缩工具
- 解压缩工具-SSZipArchive
- Linux tar --解压缩工具
- 0408学习--自增自减
- Leetcode #37. Sudoku Solver 数独求解 结题报告
- 知乎某处XSS导致刷粉-javascript的巧妙利用
- mac下apach配置需要注意的一些点
- EditText之显示密码
- 解压缩工具类
- 利用宏向excel表格中批量插入图片
- Create a custom view in Android || 在 Android 中创建一个自定义 View
- Android初级-界面编程第一篇之LinearLayout,RelativeLayout
- 微软最新账户身份验证漏洞分析-20160407-邮箱跳转后的XSS
- 基于C#反射机制的工厂模式
- 案例3计算平台长度程序
- 死循环问题窥视系统main函数初始化之前操作
- javascript 实现文件下载功能