足球游戏_中国足彩网¥体育资讯$

JSP上面实现目录压缩
来源:易贤网 阅读:893 次 日期:2015-01-27 14:41:34
温馨提示:易贤网小编为您整理了“JSP上面实现目录压缩”,方便广大网友查阅!

zip方法 zipPath参数为保存zip的文件路径 srcPath参数为需要压缩的目录 在linux window上面测试无问题!主要是编码问题比较麻烦~要是有其他异常 请留言 或者 有什么更好的方法 欢迎给中国足彩网的意见

//zip zhe folder

void zip(String zipPath, String srcPath,javax.servlet.jsp.JspWriter out) throws Exception {

FileOutputStream output = null;

ZipOutputStream zipOutput = null;

try{

output = new FileOutputStream(zipPath);

zipOutput = new ZipOutputStream(output);

zipEntry(zipOutput,srcPath,srcPath,zipPath);

}catch(Exception e){

out.print("file zip error");

}finally{

if(zipOutput!=null)zipOutput.close();

}

out.print("zip ok"+zipPath);

}

//add the zip entry

void zipEntry(ZipOutputStream zipOs, String initPath,String filePath,String zipPath) throws Exception {

String entryName = filePath;

File f = new File(filePath);

if (f.isDirectory()){// ??

String[] files = f.list();

for(int i = 0; i < files.length; i++)

zipEntry(zipOs, initPath, filePath + File.separator + files[i],zipPath);

return;

}

String chPh = initPath.substring(initPath.lastIndexOf("/") + 1);// ?????

int idx=initPath.lastIndexOf(chPh);

if (idx != -1) {

entryName = filePath.substring(idx);

}

ZipEntry entry;

entry = new ZipEntry(entryName);

File ff = new File(filePath);

if(ff.getAbsolutePath().equals(zipPath))return;

entry.setSize(ff.length());

entry.setTime(ff.lastModified());

//the CRC efficacy

entry.setCrc(0);

CRC32 crc = new CRC32();

crc.reset();

zipOs.putNextEntry(entry);

int len = 0;

byte[] buffer = new byte[2048];

int bufferLen = 2048;

FileInputStream input =null;

try{

input = new FileInputStream(filePath);

while ((len = input.read(buffer, 0, bufferLen)) != -1) {

zipOs.write(buffer, 0, len);

crc.update(buffer, 0, len);

}

}catch(Exception e){

}finally{

if(input!=null)input.close();

}

entry.setCrc(crc.getValue());

}

中国足彩网信息请查看IT技术专栏

中国足彩网信息请查看脚本栏目
易贤网手机网站地址:JSP上面实现目录压缩
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 足球游戏_中国足彩网¥体育资讯$ 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标