// 必需 @Aoutowired 利用new创立虚体无奈扫描到设置装备摆设文件招致为null
@Value("${outpath}")
private String outpath;

@Value("${pdfpath}")
private String pdfpath;

public void upload(MultipartFile filecontent) throws Exception {
OutputStream os = null;
InputStream inputStream = null;
String fileName = null;
try {
inputStream = filecontent.getInputStream();
fileName = filecontent.getOriginalFilename();
} catch (IOException e) {
e.printStackTrace();
}
try {
// 二、保留光临时文件
// 一K的数据徐冲
byte[] bs = new byte[一0二四];
// 读与到的数据少度
int len;
// 输没的文件流保留到内地文件
File tempFile = new File(pdfpath);
if (!tempFile.exists()) {
tempFile.mkdirs();
}
os = new FileOutputStream(tempFile.getPath() + File.separator + fileName);
// 合初读与
while ((len = inputStream.read(bs)) != ⑴) {
os.write(bs, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
// 终了,闭关所有链接
try {
os.close();
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

 

转自:https://www.cnblogs.com/chenTo/p/15352384.html

更多文章请关注《万象专栏》