springboot通过流的方式上传文件
yml文件路径配置
file:
path: /home/
代码
File dir = new File(path);
if (!dir.exists() && !dir.isDirectory()) {
dir.mkdirs();
}
try {
byte[] bytes = multipartFile.getBytes();
File uploadFile = new File(path + "/" + fileName);
FileOutputStream fos = new FileOutputStream(uploadFile);
BufferedOutputStream bos = new BufferedOutputStream(fos);
bos.write(bytes);
bos.flush();
bos.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}