- 7
- 0
- 约4.41千字
- 约 11页
- 2017-08-31 发布于河南
- 举报
java压缩解压文件文件夹(Java compression decompression file folder)
java压缩解压文件文件夹(Java compression decompression file folder)
Compress folders / files with Java
Zip folder code:
Import java.io.File;
Import org.apache.tools.zip.ZipOutputStream; / / this package in ant.jar, to the official website to download
Import java.io.FileInputStream;
Import java.io.FileOutputStream;
Import java.util.zip.ZipInputStream;
Import java.util.zip.ZipEntry;
Public, class, CompressBook {
Public (CompressBook) {}
/**//*
* inputFileName enter a folder
* zipFileName output a compressed folder
* /
Public, void, zip (String, inputFileName), throws, Exception {
String zipFileName = c:\\test.zip; / / package file name
System.out.println (zipFileName);
Zip (zipFileName, new, File (inputFileName));
}
Private, void, zip (String, zipFileName, File, inputFile), throws, Exception {
ZipOutputStream out = new ZipOutputStream (new, FileOutputStream (zipFileName));
Zip (out, inputFile, );
System.out.println (zip done);
Out.close ();
}
Private, void, zip (ZipOutputStream, out, File, F, String, base) throws Exception {
If (f.isDirectory ()) {
File[] FL = f.listFiles ();
Out.putNextEntry (New org.apache.tools.zip.ZipEntry (base + /));
Base = base.length (0) = =? + / : base;
For (int i = 0; I fl.length; i++) {
Zip (out, fl[i], base + fl[i].getName ());
}
}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 ();
}
}
Public static void main (String temp {[])
CompressBook book = new, CompressBook ();
{try
Book.zip (c:\\c); / / you want to compress a folder
}catch (Exception, ex) {
Ex.printStackTrace ();
}
}
}
Zip file code:
Import java.io.*;
Import java.util.zip.*; //ZipOutputStream, this stream is here
Import java.util.*;
Public class ZipOutputStreamTest
{
Public, static, void, main (String[], args) throws Exception
{
File f = new File (a.jpg);
FileInputStream FIS = new FileInputStream (f);
BufferedInputStream bis = new B
您可能关注的文档
- 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
- 24岁女工天天加管理班险致早产 想辞职就扣工资(24 year old female worker every day plus management class insurance premature birth, want to resign on deduction of wages).doc
- 25岁以后女孩怎样美容护肤(After 25 years old, how do the girls beauty skin care).doc
- 25水调歌头(25 Prelude To Water Melody).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)