0
点赞
收藏
分享

微信扫一扫

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

奋斗De奶爸 2023-12-23 阅读 39

错误写法

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

举报

相关推荐

0 条评论