JVM在写入文件XLSX崩溃

JVM在写入文件XLSX崩溃

本文介绍了JVM在写入文件XLSX崩溃(POI)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JVM是试图写入.xlsx文件崩溃。我使用的POI(XSSF)为同一个。
在code中的错误位置点是写法 - > workBook.write(FileOutputStream中);

在控制台我得到..

  A致命的错误已被Java运行时环境检测:
  SIGBUS(为0x7)在PC = 0xb68d77f3,PID = 14653,TID = 1849355120
  JRE版本:7.0_04-B20
 Java虚拟机:Java的热点(TM)服务器VM(23.0-B21混合模式的linux-X86)
 问题的框架:
 C [libzip.so + 0x47f3]新条目+ 0x73
 无法写入核心转储。核心转储已被禁用。为了使核心倾销,试试的ulimit -c无限再次启动之前的Java
 如果您想提交错误报告,请访问:
   http://bugreport.sun.com/bugreport/crash.jsp
 该事故发生在Java虚拟机之外的本土code。
 请参阅何处报告的bug问题的框架。


解决方案

我已经找到了解决的办法,我一直在寻找了一段时间,是确保你不打开你的工作簿文件您可以使用它打开的FileOutputStream 保存工作簿。相反,使用的FileInputStream 打开工作簿

这样的事会工作得很好。

  inputfile文件=新的文件(您的路径​​);
        this.inputStream =新的FileInputStream(INPUTFILE);
        this.opc = OPCPackage.open(this.inputStream);
        this.workbook = WorkbookFactory.create(OPC);...        this.outputStream =新的FileOutputStream(INPUTFILE);
        this.workbook.write(this.outputStream);

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

JVM is crashing while trying to write to the .xlsx file. I am using POI(XSSF) for the same.The error location point in code is the write method--> workBook.write(fileOutputStream);

On Console I get..

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.
解决方案

The solution I've found for this, and I've been looking for a while, is to make sure you don't open your Workbook with the File which you use to open the FileOutputStream to save the Workbook. Instead, use a FileInputStream to open the Workbook.

Something like this will work flawlessly

        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);

Don't forget to close every opened stream and the OPCPackage.

这篇关于JVM在写入文件XLSX崩溃(POI)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 01:37