for
(int i = 0; i < FileList.size(); i++) {
fileVo fileVo=FileList.get(i);
export(fileVo,request,response,title,FilePath.getPath(),fileName);
}
------
public void export(fileVo fileVo, HttpServletRequest request,
HttpServletResponse response, String title,String path, String fileName) {
FileOutputStream fileOutputStream =
null
;
try
{
File dirFile =
null
;
int i = fileVo.getName().lastIndexOf(
"."
);
if
(i!=-1){
fileName1 = fileName1 +
"."
+ (fileVo.getName()).substring(i+1);
}
boolean bFile =
false
;
String mkdirName = path + File.separatorChar + title;
dirFile =
new
File(mkdirName);
if
(!dirFile.exists()) {
dirFile.getParentFile().mkdirs();
}
if
(dirFile.isDirectory()) {
path = mkdirName + File.separatorChar + fileName1;
}
else
{
bFile = dirFile.mkdirs();
}
if
(bFile) {
path = mkdirName + File.separatorChar + fileName1;
}
fileOutputStream =
new
FileOutputStream(path.replace(
"*"
,
""
));
String fileName = URLEncoder.encode(fileName1,
"UTF-8"
);
if
(fileName.length() > 110) {
fileName =
new
String(fileName1.getBytes(
"gb2312"
),
"ISO8859-1"
);
}
response.setHeader(
"Connection"
,
"close"
);
response.setHeader(
"Content-Type"
,
"application/octet-stream"
);
response.setContentType(
"application/x-msdownload"
);
response.setHeader(
"Content-Disposition"
,
"attachment; filename=\""
+ Utf8Util.toUtf8String(fileName) +
"\""
);
fileVo.getFileIo(fileOutputStream);
fileOutputStream.close();
}
catch
(Exception e) {
logger.error(
"异常:原因如下"
+e.getMessage(), e);
} finally {
try
{
if
(fileOutputStream !=
null
) {
fileOutputStream.close();
}
}
catch
(IOException e1) {
logger.error(
"异常:原因如下"
+e1.getMessage(), e1);
}
}
}
------