4

Java中使用POI读取大的Excel文件或者输入流时发生out of memory异常参考解决方案

 2 years ago
source link: https://wakzz.cn/2018/05/18/java/Java%E4%B8%AD%E4%BD%BF%E7%94%A8POI%E8%AF%BB%E5%8F%96%E5%A4%A7%E7%9A%84Excel%E6%96%87%E4%BB%B6%E6%88%96%E8%80%85%E8%BE%93%E5%85%A5%E6%B5%81%E6%97%B6%E5%8F%91%E7%94%9Fout%20of%20memory%E5%BC%82%E5%B8%B8%E5%8F%82%E8%80%83%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Java中使用POI读取大的Excel文件或者输入流时发生out of memory异常参考解决方案

祈雨的博客
2018-05-18

excel-streaming-reader

excel-streaming-reader

Java中使用POI读取大的Excel文件或者输入流时发生out of memory异常参考解决方案

<dependency>
<groupId>com.monitorjbl</groupId>
<artifactId>xlsx-streamer</artifactId>
<version>1.2.0</version>
</dependency>
try (
InputStream is = new FileInputStream(new File("/path/to/workbook.xlsx"));
Workbook workbook = StreamingReader.builder()
.rowCacheSize(100)
.bufferSize(4096)
.open(is)) {
for (Sheet sheet : workbook){
System.out.println(sheet.getSheetName());
for (Row r : sheet) {
for (Cell c : r) {
System.out.println(c.getStringCellValue());
}
}
}
}

easyexcel

easyexcel


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK