错误写法 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();
}