我正在使用apache-poi-3.16。我试图多次写一个文件而不是一次写入但是在intelliJ idea中得到了heal dump错误。请找到以下代码供参考,
public class SampleExcelGeneration {
public static void main(String[] args) {
SampleExcelGeneration excelGeneration = new SampleExcelGeneration();
excelGeneration.writeFile();
excelGeneration.writeFile();
excelGeneration.writeFile();
excelGeneration.writeFile();
excelGeneration.writeFile();
}
private void writeFile () {
try {
final File file = new File("test.xlsx");
XSSFWorkbook wb;
XSSFSheet sheet;
if(file.exists()) {
wb = new XSSFWorkbook(file.getAbsolutePath());
sheet = wb.getSheetAt(0);
} else {
wb = new XSSFWorkbook();
sheet = wb.createSheet("Results");
}
int getLastRow = sheet.getPhysicalNumberOfRows();
int incrementLastRow = getLastRow+1;
XSSFRow row = sheet.createRow(incrementLastRow);
XSSFCell column1 = row.createCell(0);
column1.setCellValue(1);
XSSFCell column2 = row.createCell(1);
column2.setCellValue(3);
XSSFCell column3 = row.createCell(2);
column3.setCellValue(380);
XSSFCell column4 = row.createCell(3);
column4.setCellValue("sample");
XSSFCell column5 = row.createCell(4);
column5.setCellValue("value");
//write this workbook to an Outputstream.
wb.write(new FileOutputStream(file.getAbsolutePath()));
wb.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
执行在控制台中获取内容时,
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGBUS (0xa) at pc=0x000000010acbde92, pid=77146, tid=0x0000000000001003
#
# JRE version: Java(TM) SE Runtime Environment (8.0_101-b13) (build 1.8.0_101-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C [libzip.dylib+0x2e92] newEntry+0x154
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/dev/sample-excel/hs_err_pid77146.log
Compiled method (nm) 1835 100 n 0
java.util.zip.ZipFile::getEntry (native)
total in heap [0x000000010b7322d0,0x000000010b732630] = 864
relocation [0x000000010b7323f8,0x000000010b732438] = 64
main code [0x000000010b732440,0x000000010b732630] = 496
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
如果有任何其他异常意味着我可以得到一个提示来解决问题但是它会抛出堆转储错误并且它会破坏文件。
原因可能是对流的处理不当,但据我所知,我关闭了所有流。
任何帮助或暗示都会很明显。