- 关于excel文件,上传到云有两种方法(云的方法参数需要输入流)
1.先在本地生成一个文件,然后将对象写入文件里,然后再获取文件的输入流,然后调用方法上传到云,这种方法就比较蠢了
File file = new File(EXCEL_DIR + fname);
// 创建文件夹
Files.createParentDirs(file);
XSSFWorkbook wb = new XSSFWorkbook();
……
FileOutputStream fos = new FileOutputStream(file);
wb.write(fos);
// FileInputStream fileInputStream = new FileInputStream(file);
//最后在finally里记着要删除生成的文件
if (file.exists()) {
file.delete();
}
2.将对象write进内存输出流, 然后内存输出流再写出,用写出的字节构造一个内存输入流
XSSFWorkbook wb = new XSSFWorkbook();
…..
ByteArrayOutputStream bos = new ByteArrayOutputStream();
wb.write(bos);
byte[] bytes = bos.toByteArray();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);