2016-09-19 4 views
2

apache poi를 사용하여 확장명이 xlsx 인 Excel 파일을 읽는 동안 확장명을 식별하는 데 오랜 시간이 걸립니다. 왜 오랜 시간이 걸리는지 도와 주실 수 있습니까?apache poi를 사용하여 확장명이 xlsx 인 Excel 파일에서 데이터를 읽는 동안 시간이 오래 걸림

if (file.getExcelFile().getOriginalFilename().endsWith("xls")) 
    { 
    workbook = new HSSFWorkbook(file.getExcelFile().getInputStream()); 
    } else if (file.getExcelFile().getOriginalFilename().endsWith("xlsx")) 
    { 
    workbook = new XSSFWorkbook(file.getExcelFile().getInputStream()); 
    } else { 
    throw new IllegalArgumentException("Received file does not have a standard excel extension."); 
    } 
+2

Apache POI docs, use a File directly in preference to an InputStream 설명, WorkbookFactory.create(File) 그것을 할 사용해야합니까? 왜 당신은 [WorkbookFactory.create (File)] (http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/WorkbookFactory.html#create (java.io.File))을 사용하고 있지 않은가? ? – Gagravarr

+0

감사합니다. Gagrvarr이 방법으로이 문제를 해결했습니다. – Ram

답변

3

답변에 댓글을 추진 -이 너 자신을하려고하지 않는, 아파치 POI는 내장 된 코드 당신을 위해이 일을 위해!

당신은 왜 당신이 식별 자신을하고있는 예를 들어 그냥

workbook = WorkbookFactory.create(file.getExcelFile()); 

바와 같이 빠르고 낮은 메모리 처리