ZIP操作
发布日期:2021-09-30 18:11:13 浏览次数:32 分类:技术文章

本文共 1881 字,大约阅读时间需要 6 分钟。

public String prefixZip(Object obj) throws FrameException {
String str = "";
PrintWriter dataos = null;
String strPath = ServerInfo.getDownloadPath();
try
{
File file = null;
file = new File(strPath);
file.mkdirs();
Date dd = new Date();
long strD = dd.getTime();
// rvo.setretVO(PREFIXFILE + String.valueOf(strD)+".zip");
//创建文件名
str = PREFIXFILE + String.valueOf(strD) + ".zip";
StringBuffer strFullPath = new StringBuffer(strPath);
strFullPath.append(System.getProperty("file.separator"));
strFullPath.append(PREFIXFILE);
strFullPath.append(String.valueOf(strD));
strFullPath.append(".zip");
file = new File(strFullPath.toString());
TraceService.debug(LogConstants.DEPLOY,"获取压缩路径:" + strFullPath.toString());
//读取文件
ZipOutputStream zipos = new ZipOutputStream(new FileOutputStream(file));
zipos.setMethod(ZipOutputStream.DEFLATED);
zipos.putNextEntry(new ZipEntry("prefix.txt"));
dataos = new PrintWriter(zipos);
//开始处理Object,对object进行解析
if (obj instanceof MiscPrefixVO)
{
TraceService.debug(LogConstants.DEPLOY, "压缩对象为MiscPrefixVO");
dataos.print( sysCodeString(((MiscPrefixVO) obj).toString()));
}
else if (obj instanceof ArrayList)
{
int lLen = ( (ArrayList) obj).size();
TraceService.debug(LogConstants.DEPLOY,"压缩对象为ArrayList ,长度为" + lLen);
for (int i = 0; i < lLen; i++)
{
MiscPrefixVO mVO = (MiscPrefixVO) ( (ArrayList) obj).get(i);
dataos.print(sysCodeString(mVO.toString()));
dataos.flush();
}
}
dataos.close();
dataos = null;
}
catch (FileNotFoundException fne) {
if (dataos != null) {
try {
dataos.close();
}
catch (Exception e) {
}
dataos = null;
}
throw new FrameException(OAMErrorCodeConst._EC_PREFIX_ZIP_FAIL,
"压缩文件错误!" + fne.toString());
}
catch (IOException ioe) {
if (dataos != null) {
try {
dataos.close();
}
catch (Exception e) {
}
dataos = null;
}
throw new FrameException(OAMErrorCodeConst._EC_PREFIX_ZIP_FAIL,
"生成压缩文件失败!" + ioe.toString());
}
return str;
}

转载地址:https://blog.csdn.net/iteye_10361/article/details/81688590 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:流下载
下一篇:全选删除JS

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年03月31日 02时38分04秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章