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

错误写法

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

你可能感兴趣的:(java,java,mysql)