java使用zip对多级目录文件压缩及解压操作接口(Java uses zip to compress and decompress interfaces for multilevel directory files).docVIP
- 245
- 0
- 约4.63千字
- 约 17页
- 2017-08-31 发布于河南
- 举报
java使用zip对多级目录文件压缩及解压操作接口(Java uses zip to compress and decompress interfaces for multilevel directory files)
java使用zip对多级目录文件压缩及解压操作接口(Java uses zip to compress and decompress interfaces for multilevel directory files)
进口java.io.file;
进口java.io.fileinputstream;
进口java.io.fileoutputstream;
进口;
进口java.io.inputstream;
进口java.io.outputstream;
进口java.util.enumeration;
进口java.util.zip.zipentry;
进口java.util.zip.zipfile;
进口java.util.zip.zipoutputstream;
/ * *
*
* @描述:拉链解压缩文件的工具类,文件可以是多级目录的结构
*(使用JDK的zipentry存在文件名中文乱码问题,用Apache工具的则不会)
* @作者东莞分公司
* @日期2013-12-14电子邮件:dg90xf@163.com
* /
ziputil公共类
{
/ * *
*
描述:压缩文件操作* @
* @param文件路径
*要压缩的文件路径
* @param descdir
*压缩文件保存的路径
* /
public static void zipfiles(字符串的文件路径,字符串descdir)
{
zipoutputstream ZOS = null;
尝试
{
/ /创建一个拉链输出流
ZOS =新zipoutputstream(新FileOutputStream(descdir));
/ /启动压缩
startzip(ZOS,”,文件路径);
/ /系统。出来。println(“******************压缩完毕********************”);
}
赶上(次)
{
/ /压缩失败,则删除创建的文件
文件压缩文件为新文件(descdir);
如果(压缩文件。exists())
{
delete()压缩文件;
}
/ /系统。出来。println(“******************压缩失败********************”);
E. printstacktrace();
}
最后
{
尝试
{
如果(ZOS!= null)
{
ZOS。();
}
}
赶上(次)
{
E. printstacktrace();
}
}
}
/ * *
*
描述:对目录中所有文件递归遍历进行压缩* @
* @param ZOS
*拉链压缩输出流
* @param oppositepath
*在拉链文件中的相对路径
* @param目录
*要压缩的文件的路径
* @抛出IOException
* /
私有静态startzip(zipoutputstream ZOS,字符串oppositepath,
字符串目录)抛出IOException
{
xml文件的新文件(目录);
如果(文件。isdirectory())
{
/ /如果是压缩目录
文件文件文件listfiles() [ ];
为(int i = 0;i files.length;i++)
{
文件文件=文件[我];
如果(文件。isdirectory())
{
/ /如果是目录,修改相对地址
字符串newoppositepath = oppositepath +一个getname() +“/”;
/ /压缩目录,这是关键,创建一个目录的条目时,需要在目录名后面加多一个”/“
zipentry入门=新zipentry(oppositepath +文件。getname() +“/”);
ZOS putnextentry(进入);
closeentry() ZOS;
/ /进行递归调用
startzip(ZOS,newoppositepath,文件。
GetPath ());
}
Else
{
/ / if not a directory, then compression
ZipFile (zos, oppositePath, aFile);
}
}
}
Else
{
If / is compressed files, directly call compression method
ZipFile (zos, oppositePath, file);
}
}
/ * *
*
* @description: compress a single file into a directory
* @param zos
* zip output stream
* @param oppositePath
* the relative path in the z
您可能关注的文档
- 210个字谜灯谜(210 puzzle lantern riddles).doc
- 21世纪想成功必看的——网商经(Twenty-first Century - net business must want to succeed).doc
- 21招 让脂肪燃烧大提速(21 strokes so that fat burning speed).doc
- 21yod 2011-8-24 74632 药店名称订单总数发货数甘肃德生堂医药(21yod 2011-8-24 74632 the total number of orders shipped Gansu drugstore name deshengtang medicine).doc
- 2014香港标杆房企住宅、豪宅、别墅及商业地产考察(9月26-28日)(2014 Hongkong benchmark housing prices, residential, luxury, villas and commercial real estate inspection (September 26-28)).doc
- 220th水冷方形分离器循环流化床锅炉的设计及运行(Design and operation of 220th water-cooled square separator circulating fluidized bed boiler).doc
- 23万余条意见里的百企业培训姓视角 个税改革三大焦点(More than 23 views of 100 enterprises training, surname perspective, tax reform focus of three).doc
- 23万余条意见里的百姓视角 个税改革三大焦点(More than 23 views of the people in the views of three major focus of tax reform).doc
- 24小时人体使用手册(24 hour manual for human use).doc
- 25 催运货物(25 freight forwarding).doc
- 小区绿化施工协议书.docx
- 墙面施工协议书.docx
- 1 古诗二首(课件)--2025-2026学年统编版语文二年级下册.pptx
- (2026春新版)部编版八年级道德与法治下册《3.1《公民基本权利》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《4.3《依法履行义务》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《6.2《按劳分配为主体、多种分配方式并存》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《6.1《公有制为主体、多种所有制经济共同发展》PPT课件.pptx
- 初三教学管理交流发言稿.docx
- 小学生课外阅读总结.docx
- 餐饮门店夜经济运营的社会责任报告(夜间贡献)撰写流程试题库及答案.doc
最近下载
- ISO9001-2026质量管理体系标准版中英文及变化点解析.pdf VIP
- HGT 21629-1999 管架标准图(四).docx VIP
- 广州市民办学校申办审批表.doc VIP
- 无人机测绘技术与应用课件21--无人机驾驶员职业规划.ppt
- 2025年袋鼠数学LevelB试卷及答案.pdf VIP
- 《重症凝血病标准化评估中国专家共识(2025)》解读PPT课件.pptx VIP
- 《动物防疫法》培训解读课件.pptx VIP
- 无人机测绘技术与应用课件20--无人机飞行原理.ppt
- 先进控制技术及其应用.docx VIP
- 2025-2026学年济南版(2024)初中生物八年级上册《血液是物质运输的载体》教学设计.docx
原创力文档

文档评论(0)