jsp 批量下载文件夹/文件(j解决中文乱码问题)

最近,一直在研究批量下载的问题,刚开始的想法是批量选择文件后,点击下载按钮,会弹出一个路径选择框,选择路径后,几个文件同时下载下来...研究了一段时间,发现自己是菜鸟,实现不鸟呀...
后来,是在没办法,就想实现批量打包下载,不管是文件夹,还是文件,都能批量下载.经过我一天半的努力,终于实现啦 :P
批量压缩文件夹/文件的代码如下:
   
public void ZipFiles(java.io.File[] srcfile,java.io.File zipfile){
byte[] buf = new byte[1024];
try{
//create the zip file
org.apache.tools.zip.ZipOutputStream out = new org.apache.tools.zip.ZipOutputStream(new FileOutputStream(zipfile));
out.setEncoding("gbk");
//Compress the files
for(int i = 0; i < srcfile.length;i++){
String path = srcfile[i].getName();
zip(out,srcfile[i],path);
}
//Complete the zip file
out.close();
}catch(IOException e){
e.printStackTrace();
}

}

private void zip(org.apache.tools.zip.ZipOutputStream out,File f,String base){
try{
if(f.isDirectory()){
File[] f1 = f.listFiles();
out.putNextEntry(new org.apache.tools.zip.ZipEntry(base+"/"));
base=base + "/";
for(int i = 0; i <f1.length; i++){
zip(out,f1[i],base + f1[i].getName());
}
}else{
String fileName=f.getName();
int index = 0;
index = fileName.lastIndexOf(".");
String sub = fileName.substring(index+1);
if(!sub.equals("crc")){
out.putNextEntry(new org.apache.tools.zip.ZipEntry(base));
FileInputStream in = new FileInputStream(f);
byte[] buf = new byte[1024];
int b;
while((b = in.read(buf))>0){
out.write(buf,0,b);
}
in.close();
}
}
}catch(IOException e){
e.printStackTrace();
}
}


因为我的文件夹是存在hadoop上的,为了办证数据的完整性,hadoop使用了CRC数据校验。会对每一个文件产生对应的filename.crc文件。故我需要识别出.crc文件,不对其进行打包...
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值