【问题标题】:JVM crashing while writing to XLSX file( POI)写入 XLSX 文件 (POI) 时 JVM 崩溃
【发布时间】:2012-07-05 12:14:43
【问题描述】:

JVM 在尝试写入 .xlsx 文件时崩溃。我也在使用 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.

【问题讨论】:

  • 如果错误是准确的,这似乎是 POI 库中的一个错误(启用核心转储会很有用)。为什么不直接向项目提交错误报告?他们会更好地了解如何调试它。
  • 你可以尝试通过你的包管理器更新 libzip。
  • 尝试 Java 7 update 5 并确保您的驱动器上有足够的可用空间。
  • Apache POI 是纯 Java,因此永远不会触发 JVM 崩溃。这看起来像是 JVM 本身的错误,您需要向 Oracle 报告
  • 是时候向 Oracle 报告错误了。任何 Java 程序都不应该让 JVM 崩溃,所以你发现了一个 JVM 错误

标签: java crash jvm apache-poi jvm-crash


【解决方案1】:

我为此找到的解决方案,并且我一直在寻找一段时间,是确保您不要使用用于打开 FileOutputStreamFile 打开您的 Workbook 到保存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

【讨论】:

    【解决方案2】:

    其他解决方案都不适合我。我只需要对我的 Excel 文件进行只读访问,并且设置只读标志对我有用:

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

    【讨论】:

      【解决方案3】:

      使用 OPCPackage 并没有为我修复 JVM 崩溃,但使用 WorkbookFactory 可以。如果您查看POI Busy Developers Guide,他们提供了读取和写入相同 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 版、Java 1.8

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-12
      • 1970-01-01
      • 2016-09-07
      相关资源
      最近更新 更多