티스토리 뷰

기존 소스를 보면 FileOutputStream 을 생성하고 엑셀 파일을 만든 후 다운로드 처리를 합니다.  

그런데 엑셀 파일을 생성하는 중에 OutOfMemory가 발생했습니다. 

해당 소스가 직접적인 원인은 아니지만 개선의 여지가 있습니다. 

파일을 생성하고 그걸 다운로드로 연결해서 다시 파일을 읽고 다운로드하던 것을 바로 다운로드 하게끔 바꿨습니다. 


2
3
4
5
6
7
8
9
10
11
        XSSFWorkbook workbook = new XSSFWorkbook();
        ... 
 
        String filename = "customer_"+System.currentTimeMillis()+".xlsx";
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition""attachment; filename="+filename);
        try(OutputStream os=response.getOutputStream();) {
            workbook.write(os);
        } catch (IOException ie) {
            log.error(ie.getMessage());
        }
cs


정상 작동 확인. 

끝~~~ 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함