JVM 在尝试写入 .xlsx 文件时崩溃。我正在使用 POI(XSSF) 来做同样的事情。
代码中出错的位置点是write 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.
最佳答案
我为此找到的解决方案(我已经寻找了一段时间)是确保您不会使用 File
打开您的 Workbook
用于打开 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
。
关于java - 写入 XLSX 文件 (POI) 时 JVM 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11344131/