JVM在写入XLSX文件崩溃(POI)(JVM crashing while writing to

2019-07-30 06:18发布

而试图写入.xlsx文件JVM崩溃。 我使用的POI(XSSF)为同一。 在代码错误位置点是写入method--> workBook.write(fileOutputStream);

在控制台我得到..

A fatal error has been detected by the Java Runtime Environment:
  SIGBUS (0x7) at pc=0xb68d77f3, pid=14653, tid=1849355120
  JRE version: 7.0_04-b20
 Java VM: Java HotSpot(TM) Server VM (23.0-b21 mixed mode linux-x86 )
 Problematic frame:
 C  [libzip.so+0x47f3]  newEntry+0x73
 Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
 If you would like to submit a bug report, please visit:
   http://bugreport.sun.com/bugreport/crash.jsp
 The crash happened outside the Java Virtual Machine in native code.
 See problematic frame for where to report the bug.

Answer 1:

该解决方案,我发现这一点,我一直在寻找了一段时间,是确保你不打开WorkbookFile您可以使用它打开FileOutputStream保存Workbook 。 相反,使用FileInputStream打开Workbook

像这样的东西都会工作得很好

        File inputFile = new File("Your-Path");
        this.inputStream = new FileInputStream(inputFile);
        this.opc = OPCPackage.open(this.inputStream);
        this.workbook = WorkbookFactory.create(opc);

...

        this.outputStream = new FileOutputStream(inputFile);
        this.workbook.write(this.outputStream);

不要忘记关闭每个打开的流和OPCPackage



Answer 2:

其他解决方案都没有为我工作。 我只需要只读访问我的Excel文件,并设置只读标志为我工作:

Workbook wb = new XSSFWorkbook(OPCPackage.open(file, PackageAccess.READ));
Workbook wb = new HSSFWorkbook(new POIFSFileSystem(file, true));


Answer 3:

使用OPCPackage没有解决JVM崩溃了我,但使用WorkbookFactory做到了。 如果你看一下POI忙开发人员指南他们提供例如读取和写入同一个Excel文件。

File excelFile = new File("workbook.xlsx");

InputStream inp = new FileInputStream(excelFile);
Workbook wb = WorkbookFactory.create(inp);

FileOutputStream fileOut = new FileOutputStream(excelFile);
wb.write(fileOut);
fileOut.close();

使用Apache POI 3.13版本,1.8的Java



文章来源: JVM crashing while writing to XLSX file( POI)