OutOfMemoryError:要上载8 MB大小文件的Java堆空间

R T*_*ari 5 grails groovy out-of-memory apache-poi

我正在使用Grails 2.4.4并尝试使用'apache poi'插件上传.xlsx文件,但是当文件大小约为8 MB时,我得到JAVA堆大小异常.

我的控制器具有以下操作和方法: -

def uploadForm() {       
       String fileName = "D:\\File.xlsx"
       Map excelSheetMap = process(fileName)
}

Map process(String fileName) {
    ExcelBuilder excelBuilder = new ExcelBuilder(fileName)  
    //Getting JAVA Heap Size exception here when I am trying to create an object 
    //of ExcelBuilder with the file      
}
Run Code Online (Sandbox Code Playgroud)

ExcelBuilder.groovy类文件看起来像这样

class ExcelBuilder {
   Workbook workbook
   ExcelBuilder(String fileName) {      
      new File(fileName).withInputStream { is ->
         workbook = new XSSFWorkbook(is)
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

我也试过使用grails-excel-import插件,但是我得到了同样的例外.

有人可以建议如何导入grails中的大尺寸excel文件.提前致谢.

Pri*_*tre 0

Poi 确实有很高的内存占用。请参阅: http: //poi.apache.org/spreadsheet/index.html

你可以试试SXSSF。SXSSF 是 XSSF 的 API 兼容流扩展,在必须生成非常大的电子表格且堆空间有限时使用。