将MultipartFile转化成File
前言
将MultipartFile转化成File
案例
// 文件流转换
public String MultipartFile2File(MultipartFile file, String fileName) throws IOException {
InputStream fis = file.getInputStream();
//目标地址
FileOutputStream fos = new FileOutputStream(fileName);
byte[] b = new byte[1024 * 10];
//读取长度
int len = 0;
//循环读取数据
while ((len = fis.read(b)) != -1) {
fos.write(b, 0, len);
}
//释放资源
fis.close();
fos.close();
log.info("MultipartFile2File temporary documents name {}", fileName);
return fileName;
}