java JVM在写入XLSX文件(POI)时崩溃
JVM在尝试写入时崩溃。xlsx文件。我正在使用POI(XSSF)进行同样的操作。
代码中的错误位置点是writemethod--> 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.
# 1 楼答案
我已经找到了解决这个问题的方法,并且我已经寻找了一段时间,就是确保你不会用
File
打开你的Workbook
,你用它来打开FileOutputStream
来保存Workbook
。相反,使用FileInputStream
打开Workbook
像这样的东西可以完美地工作
不要忘记关闭每个打开的流和
OPCPackage
# 2 楼答案
其他的解决方案都不适合我。我只需要对Excel文件进行只读访问,设置只读标志对我很有效:
# 3 楼答案
使用
OPCPackage
并没有为我修复JVM崩溃,但使用WorkbookFactory
修复了。如果您查看POI Busy Developers Guide,它们提供了读取和写入同一Excel文件的示例使用ApachePOI版本3.13、Java1.8