728x90
파일 다운로드 [ JAVA ]
일반적으로 많이 쓰는 파일 다운로드 모듈이다.
/**
* 지정된 파일을 다운로드 한다.
*
* @param request
* @param response
* @param file
* 다운로드할 파일
*
* @throws ServletException
* @throws IOException
*/
public static void download(HttpServletRequest request, HttpServletResponse response, File file, String fileNm)
throws ServletException, IOException {
String mimetype = request.getSession().getServletContext().getMimeType(file.getName());
if (file == null || !file.exists() || file.length() <= 0 || file.isDirectory()) {
throw new IOException("파일 객체가 Null 혹은 존재하지 않거나 길이가 0, 혹은 파일이 아닌 디렉토리이다.");
}
InputStream is = null;
try {
is = new FileInputStream(file);
download(request, response, is, fileNm, file.length(), mimetype);
} finally {
try {
is.close();
} catch (Exception ex){}
}
}
728x90
'개발 > WEB PROGRAMMING' 카테고리의 다른 글
[ JAVASCRIPT ] STRING 객체 특수기호를 HTML 형식에 맞춰 변환 (0) | 2020.11.10 |
---|---|
[ JAVASCRIPT ] 문자열 길이 바이트 제한수 체크하는 함수 (0) | 2020.11.09 |
[ JAVASCRIPT ] Cookie 관리해보자! 실개발 코딩하기 - Let's manage cookies! Real development coding (0) | 2020.11.07 |
JAVASCRIPT 문자열 값 체크 (값이 없는 경우 false 반환) (0) | 2020.11.06 |
[ 공통 ] javascript String 객체 Util성(실개발자 유용한 꿀팁) (0) | 2020.03.26 |
댓글