Atitit java zip compress use apache tool jar 压缩的问题 static void zip(java.lang.String zipFileName,
Atitit java zip compress use apache tool jar
压缩的问题
static void |
zip(java.lang.String zipFileName, java.lang.String absolutPath_waittoProcessFileOrDir) |
只应该这俩个参数。。网上的在多重目录下有bug,花了好长时间修复bug
应该啊abs path的目录作为一个文件来看待所以,zip root diras source dir name
package com.attilax.compress;
import static org.junit.Assert.*;
import org.junit.Test;
public class ZipUtilTest {
@Test
public void testZip() {
//ZipUtil.zip("c:\\d\\placeholderIndex_v7_frm_java.zip", "", "C:\\d\\placeholderIndex v3 s524");
ZipUtil.zip("c:\\d\\placeholderIndex_v7_frm_java.zip", "C:\\d\\war");
System.out.println("-f");
}
}
private static void |
close_isNos(java.io.OutputStream os, java.io.InputStream is, org.apache.tools.zip.ZipFile zipFile) |
private static void |
createZipNode(org.apache.tools.zip.ZipOutputStream zos, java.lang.String relativePath) 创建目录 |
private static java.lang.String |
getnewRelativePathByDirjoin(java.lang.String relativeRootPath_inzip, java.lang.String name) |
static void |
main(java.lang.String[] args) |
static java.lang.String |
unzip_filelist(java.lang.String zipFilePath) 解压缩zip包 |
static java.util.List<java.lang.String> |
unzip_filelistV2(java.lang.String zipFilePath) |
static void |
unzip_throwRE(java.lang.String zipFilePath, java.lang.String targetPath) |
static void |
unzip(java.lang.String zipFilePath, java.lang.String targetPath) 解压缩zip包 |
static void |
unzipV2(java.lang.String zipFilePath, java.lang.String targetPath) 解压缩zip包 |
static void |
unzipV3(java.lang.String zipFilePath, java.lang.String targetPath, com.google.common.base.Function runnableImp) 解压缩zip包 |
static void |
unzipZipoisit(java.lang.String zipFilePath) |
static void |
unzipZipoisit(java.lang.String zipFilePath, com.google.common.base.Function runnableImp) upzip to cur dir |
private static void |
upzipSingle(org.apache.tools.zip.ZipFile zipFile, java.lang.String directoryPath, org.apache.tools.zip.ZipEntry zipEntry) |
private static void |
upzipSingleOutput(org.apache.tools.zip.ZipFile zipFile, org.apache.tools.zip.ZipEntry zipEntry, java.io.File targetFile) |
static void |
zip(java.lang.String zipFileName, java.lang.String absolutPath_waittoProcessFileOrDir) |
static void |
zip(java.lang.String zipFileName, java.lang.String relativePath_inzip, java.lang.String absolutPath_waittoProcessFileOrDir) 压缩 |
private static void |
zip(org.apache.tools.zip.ZipOutputStream zos, java.lang.String relativeRootPath_inzip, java.lang.String absolutPath_waittoProcessFileOrDir, java.lang.String Startdir) 压缩 |
private static void |
zipFile(org.apache.tools.zip.ZipOutputStream zos, java.io.File file, java.lang.String relativePath_inzip, java.lang.String startdir) 压缩文件 |
public class ZipUtil {
protected static Logger logger = LoggerFactory.getLogger(ZipUtil.class);
public static void zip(String zipFileName, String absolutPath_waittoProcessFileOrDir) {
File file = new File(absolutPath_waittoProcessFileOrDir);
String Startdir = file.getParent();
ZipOutputStream zos = null;
try {
zos = new ZipOutputStream(new FileOutputStream(zipFileName));
} catch (FileNotFoundException e1) {
ExUtil.throwExV2(e1);
}
try {
zip(zos, "", absolutPath_waittoProcessFileOrDir, Startdir);
} catch (Exception ex) {
ExUtil.throwExV2(ex);
} finally {
if (null != zos) {
try {
zos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
/** */
/**
* 压缩
*
* @param zipFileName
* 压缩产生的zip包文件名--带路径,如果为null或空则默认按文件名生产压缩文件名
* @param relativePath_inzip
* 相对路径,默认为空
* @param absolutPath_waittoProcessFileOrDir
* 文件或目录的绝对路径
* @throws FileNotFoundException
* @throws IOException
* @author yayagepei
* @date 2008-8-26
*/
public static void zip(String zipFileName, String relativePath_inzip, String absolutPath_waittoProcessFileOrDir) {
File file = new File(absolutPath_waittoProcessFileOrDir);
String Startdir = file.getParent();
ZipOutputStream zos = null;
try {
zos = new ZipOutputStream(new FileOutputStream(zipFileName));
} catch (FileNotFoundException e1) {
ExUtil.throwExV2(e1);
}
try {
zip(zos, relativePath_inzip, absolutPath_waittoProcessFileOrDir, Startdir);
} catch (Exception ex) {
ExUtil.throwExV2(ex);
} finally {
if (null != zos) {
try {
zos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
/** */
/**
* 压缩
*
* @param zos
* 压缩输出流
* @param relativeRootPath_inzip
* 相对路径
* @param absolutPath_waittoProcessFileOrDir
* 文件或文件夹绝对路径
* @throws IOException
* @author yayagepei
* @date 2008-8-26
*/
// private static void zip(ZipOutputStream zos, String
// relativeRootPath_inzip, String absolutPath_waittoProcessFileOrDir) {
// File file = new File(absolutPath_waittoProcessFileOrDir);
// String Startdir=file.getParent();
// zip(zos, relativeRootPath_inzip,absolutPath_waittoProcessFileOrDir,
// Startdir);
//
// }
private static void zip(ZipOutputStream zos, String relativeRootPath_inzip,
String absolutPath_waittoProcessFileOrDir, String Startdir) {
File file = new File(absolutPath_waittoProcessFileOrDir);
if (file.isDirectory()) { // lev1
// createZipNode(zos, file.getName()+"");
File[] files = file.listFiles();
// relativeRootPath_inzip= getnewRelativePathByDirjoin(
// relativeRootPath_inzip , file.getName());
for (int i = 0; i < files.length; i++) {
File tempFile = files[i];
if (tempFile.isDirectory()) { // lev2
zip(zos, relativeRootPath_inzip, tempFile.getPath(), Startdir);
} else { // file mode
zipFile(zos, tempFile, relativeRootPath_inzip, Startdir);
}
}
} else {
zipFile(zos, file, relativeRootPath_inzip, Startdir);
}
}
private static String getnewRelativePathByDirjoin(String relativeRootPath_inzip, String name) {
if (relativeRootPath_inzip == null)
return name;
if (relativeRootPath_inzip.trim().length() == 0)
return name;
else
return relativeRootPath_inzip + File.separator + name;
}
/** */
/**
* 压缩文件
*
* @param zos
* 压缩输出流
* @param file
* 文件对象
* @param relativePath_inzip
* 相对路径
* @throws IOException
* @author yayagepei
* @param startdir
* @date 2008-8-26
*/
private static void zipFile(ZipOutputStream zos, File file, String relativePath_inzip, String startdir) {
logger.info(file.getAbsolutePath());
String rltpath = file.getAbsolutePath().substring(startdir.length() + 1);
String ZipEntrynamej = getnewRelativePathByDirjoin(relativePath_inzip, rltpath);
ZipEntry entry = new ZipEntry(ZipEntrynamej);
try {
zos.putNextEntry(entry);
} catch (IOException e) {
ExUtil.throwExV2(e);
}
InputStream is = null;
try {
is = new FileInputStream(file);
int BUFFERSIZE = 2 << 10;
int length = 0;
byte[] buffer = new byte[BUFFERSIZE];
while ((length = is.read(buffer, 0, BUFFERSIZE)) >= 0) {
zos.write(buffer, 0, length);
}
zos.flush();
zos.closeEntry();
} catch (IOException ex) {
ExUtil.throwExV2(ex);
} finally {
if (null != is) {
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Atitit java zip compress use apache tool jar 压缩的问题 static void zip(java.lang.String zipFileName,相关推荐
- Linux + JAVA得到各种格式的文件正文(office文件,PDF,邮件,html,zip等)
在文件数据挖掘处理技术中,如何从文本数据中抽取有价值的信息和知识是一个重要的数据挖据分支,是机器学习.自然语言处理.数理统计的基础技术之一,是信息检索,机器学习,AI智能等高端技术的的底层技术支持之一 ...
- java.util.ServiceConfigurationError: org.apache.juli.logging.Log: Provider org.eclipse.jetty.apache.
在用maven项目的时候,项目原本部署在 Tomcat 服务器上,一切正常,但是部署到 Jetty 后,启动报错.关键错误信息为 "java.lang.NoClassDefFoundErro ...
- java 压缩技术_Java压缩技术(三) ZIP解压缩——Java原生实现
JavaEye的朋友跟我说:"你一口气把ZIP压缩和解压缩都写到一个帖子里,我看起来很累,不如分开好阅读".ok,面向读者需求,我做调整,这里单说ZIP解压缩! 相关链接: Jav ...
- java.lang.String cannot be cast to org.apache.flink.table.data.StringData
完整报错: 16:54:56,851 INFO org.apache.hadoop.conf.Configuration.deprecation - io.bytes.per.checksum is ...
- Java压缩技术(三) ZIP解压缩——Java原生实现
转载自 Java压缩技术(三) ZIP解压缩--Java原生实现 解压缩与压缩运作方式相反,原理大抵相同,由ZipInputStream通过read方法对数据解压,同时需要通过CheckedInp ...
- Java压缩技术(四) GZIP——Java原生实现
转载自 Java压缩技术(四) GZIP--Java原生实现 GZIP常常用在linxu环境下,是一种非常简单的压缩算法.在Java实现API中,它仅仅包含两个实现类:GZIPInputStream ...
- java字段描述符_Java 的方法签名与字段类型表示-[Ljava.lang.String;
我们什么时候会接触到 Java 的方法签名呢?在进行 JNI 调用时,还有在看方法重载时.重载的方法是有不同的方法签名的,而是不区分返回值,而实际方法签名还揉入了返回值类型的,还有就是 javap - ...
- SpringBoot 提示转换异常:java.lang.ClassCastException: com.*** cannot be cast to java.lang.String
功能要求:查看之前自己编写的Controller层没有通用响应,所以基于Spring Aop 面向切面添加统一结果输出. 上述功能实现后,进行简单的单元测试,出现如下错误: java.lang.Cla ...
- android在java下建立模块,Android Studio:如何在Android模块中包含Java模块?
在Android工作室我有一个Android模块,我们称之为MyAndroid.我还有一个Java模块(不是独立的JAR,而是模块中的完整Java项目),我们称之为MyJava.Android Stu ...
- AS3的一些压缩解压缩类库(AS3 ZIP、AS3 GZIP等等)
原文链接:AS3的一些压缩解压缩类库(AS3 ZIP.AS3 GZIP等等) 在现在开发的游戏中,由于战斗数据比较大,所以尝试对战斗数据进行压缩,然后输出到客户端flash端再解压. Google到一 ...
最新文章
- 钻进眼球的致盲寄生虫威胁近亿人,却只是生存竞争的失败者
- java websocket 上传大文件,使用java websocket API和Javascript上传文件
- 在 .NET Compact Framework 2.0 中宿主 ActiveX 控件
- PHP查看PECL模块包含的函数
- python指定变量类型_Python#160;变量类型_python教程
- SecureCRT连接linux时主机名,secureCRT连接linux方法
- 如何高效地使用51单片机串口输入输出
- python读取文件乱码
- 计算机的时间和dc的时间不同步_时间同步配置,让你轻松同步所有设备时间,让日志信息更有价值...
- Java IO学习笔记总结
- ireport 分页配置每也显示多少条_最简洁的分页插件PageHelper
- java导出简单写法
- json数组转换成java对象_json中包含json数组怎么转换成java对象
- 中海达数据怎么转rinex_GPS_OEM原始数据向Rinex格式转换的方法[1]
- 3分钟快速了解猪齿鱼权限
- maven依赖名词解释
- Travis CI 持续集成工具 教程
- 复数乘法的交换律、结合律及乘法 对加法的分配律证明过程
- linux发送短信的脚本,shell监控系统资源并通过短信报警的脚本
- 两个表格合并怎么做?
热门文章
- win7系统网络计算机,Win7系统打开局域网没看到其他计算机的修复方法
- 迭代器修改元素_设计模式-迭代器模式
- 参考官方mysql自定义一个mysql sink connector
- Kafka技术资料总结(不断更新中)
- Kafka 学习笔记(二) :初探 Kafka
- openstack-O版-glance安装
- sqlserver无ldf日志文件附加的方法(数据库没有完全关闭,无法重新生成日志)...
- OSChina 周二乱弹 —— 我国领先世界的IT技术
- nginx 安全加固心得
- MySQL 之 Metadata Locking 研究