파일 명을 다운로드할 경우 다음과 같이 인코딩을 하면 된다.
String fileName = request.getParameter("fileName");
String fileMask = request.getParameter("fileMask");
// 서버폴더명
String savePath = Constants.UPLOADPATH_BBS;
// Download file
File file = new File(savePath + File.separatorChar + fileMask); // 절대경로입니다.
byte b[] = new byte[(int) file.length()];
fileName = URLEncoder.encode(fileName, "UTF-8");
response.setContentType("Content-type: application/x-msdownload;");
response.setHeader("Content-Disposition", "attachment; filename="
+ fileName);
logger.debug("download path : " + savePath + File.separatorChar + fileMask);
if (file.isFile()) {
BufferedInputStream fin = null;
BufferedOutputStream outs = null;
int read = 0;
try {
fin = new BufferedInputStream(new FileInputStream(file));
outs = new BufferedOutputStream(response.getOutputStream());
while ((read = fin.read(b)) != -1) {
outs.write(b, 0, read);
}
outs.close();
fin.close();
} catch (Exception e) {
logger.error(e.getMessage(), e);
frm.setResultMsg(bundle.getMessage(getLocale(request), "SYSCommConInqAL.msg.error.fileDownload"));
} finally {
if (outs != null)
outs.close();
if (fin != null)
fin.close();
}
}