当前位置 : 主页 > 编程语言 > java >

【poi】使用poi时报错:java.io.EOFException: Unexpected end of ZLIB input stream

来源:互联网 收集:自由互联 发布时间:2023-12-28
错误写法 Workbook workbook = null;try { // 会报错 File file = new File("D:\\1.xlsx"); workbook = new XSSFWorkbook(file); ByteArrayOutputStream baos = new ByteArrayOutputStream();workbook.write(baos);workbook.close();bytes = baos.toBy

错误写法

Workbook workbook = null;
try {
    // 会报错
    File file = new File("D:\\1.xlsx");
    workbook = new XSSFWorkbook(file);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
	workbook.write(baos);
	workbook.close();
	bytes = baos.toByteArray();
} catch (Exception e) {
    e.printStackTrace();
}

正确写法

Workbook workbook = null;
try {
	File file = new File("D:\\1.xlsx");
    workbook = new XSSFWorkbook(new FileInputStream(file));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
	workbook.write(baos);
	workbook.close();
	bytes = baos.toByteArray();
} catch (Exception e) {
    e.printStackTrace();
}
上一篇:synchronized 锁粒度
下一篇:没有了
网友评论