错误写法
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();
}
标签:Unexpected,java,File,ByteArrayOutputStream,poi,file,baos,workbook,new
From: https://blog.51cto.com/u_16421711/8944957