我正在尝试使用Apache POI
和OPCPackage
编辑excel文件,但由于一些奇怪的原因,我无法正常工作。以下是代码段:
File file = new File(basePath, fileName);
int currentColNum=0, currentRowNum=0;
OPCPackage pkg = null;
Workbook wb = null;
if(file.exists())
pkg = OPCPackage.open(file);
wb = new XSSFWorkbook(pkg);
else
wb = new XSSFWorkbook();
Sheet sheet = wb.getSheet(sheetName);
if(sheet==null)
sheet = wb.createSheet(sheetName);
else
currentRowNum = lastWrittenRowCol.get(sheetName).getLeft();
for(Entry<?,?> entry : map.entrySet()) {
//some code. This code uses functions like sheet.createRow() etc.
}
FileOutputStream out = new FileOutputStream(file);
System.out.println("before write.out"); //Printed/
wb.write(out);
System.out.println("last statement"); //Not printed.
out.close();
if(pkg!=null)
pkg.close();
我收到以下错误:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGBUS (0x7) at pc=0x00002b517248dae2, pid=14557, tid=47628802967872
#
# JRE version: 7.0_25-b15
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.25-b01 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libzip.so+0x4ae2] newEntry+0x62
#
# 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.
#
这是日志中的内存信息:
/proc/meminfo:
MemTotal: 5855708 kB
MemFree: 1413996 kB
Buffers: 815896 kB
Cached: 1939120 kB
SwapCached: 0 kB
Active: 2339452 kB
Inactive: 1512396 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 5855708 kB
LowFree: 1413872 kB
SwapTotal: 5140792 kB
SwapFree: 5140792 kB
Dirty: 5556 kB
Writeback: 0 kB
AnonPages: 1096860 kB
Mapped: 112944 kB
Slab: 520072 kB
PageTables: 39008 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
CommitLimit: 8068644 kB
Committed_AS: 2106544 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 51844 kB
VmallocChunk: 34359686179 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
Hugepagesize: 2048 kB
我正在使用Eclipse。程序使用参数-Xms512m -Xmx2048m
运行。 wb.write(out)
存在一些问题,因为在该行之前的语句被打印但是下一行不是。 (我知道我应该使用调试器,但我不知道如何在我们的构建系统的eclipse中插入它)。任何帮助表示赞赏!
答案 0 :(得分:0)