반응형
String real = propertyService.getString("Globals.fileStorePath");
String mimetype = "application/x-msdownload";
String fileName = "다운로드 될 파일명";
File downFile = new File(real+File.separator+"","저장소 파일명");
int fSize = (int)downFile.length();
if(!downFile.exists()) {
return;
}
response.setBufferSize(fSize);
response.setContentType(mimetype);
setDisposition(fileName, request, response);
response.setContentLength(fSize);
FileInputStream fis = null;
FileChannel ins = null;
WritableByteChannel out = null;
try{
fis = new FileInputStream(downFile);
ins = fis.getChannel();
out = Channels.newChannel(response.getOutputStream());
ins.transferTo(0,ins.size(),out);
}catch(Exception e){
e.printStackTrace();
}finally {
try{if(out != null) out.close();}catch(Exception e){e.printStackTrace();}
try{if(ins != null) ins.close();}catch(Exception e){e.printStackTrace();}
try{if(fis != null) fis.close();}catch(Exception e){e.printStackTrace();}
}
반응형
'Backend > Java' 카테고리의 다른 글
JSTL 시간 select list (0) | 2020.11.09 |
---|---|
JSTL 년도 select List (0) | 2020.11.09 |
properties && @Value 사용하기 (0) | 2020.09.04 |
BufferedReader (0) | 2020.07.28 |
URL 호출 (0) | 2020.07.07 |