//使用org.apache.tools.zip包
public void ExportRARTest(String tablename[],HttpServletRequest request,String dir,String fileFolder,String isback) throws IOException{
byte[] buf = new byte[1024];
org.apache.tools.zip.ZipOutputStream out = new org.apache.tools.zip.ZipOutputStream(new FileOutputStream(dir));
String pathString="";
if ("yes".equals(isback)) {
pathString=fileString+fileFolder;
}
else {
pathString=request.getRealPath("/")+"updbload";
}
try {
for(int i=0;i<tablename.length;i++) {
tablename[i]=pathString+"/"+tablename[i];
File file=new File(tablename[i]);
if (file.exists()) {
FileInputStream fis = new FileInputStream(file);
out.putNextEntry(new org.apache.tools.zip.ZipEntry(file.getName()));
int len;
//读入需要下载的文件的内容,打包到zip文件
while((len = fis.read(buf))>0) {
out.write(buf,0,len);
}
out.closeEntry();
fis.close();
file.delete();
}
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
finally{
out.close();
}
}
注意黑体<Strong></Strong>部分是解决中文乱码的关键!!!!!!