方法一:
//上传文件方法
public void uploadUtil(MultipartFile,String filepath,String filename) throws IOException {
File uploadDir = new File(filepath);
if(!uploadDir.exists()) {
uploadDir.mkdirs();
}
File servfile = new File(filepath+filename);
file.transferTo(servfile);
}
方法二:
//上传文件方法
public void uploadUtil(byte[] file,String filepath,String filename) throws IOException {
File uploadDir = new File(filepath);
if(!uploadDir.exists()) {
uploadDir.mkdirs();
}
FileOutputStream outputStream = new FileOutputStream(filepath+filename);
outputStream.write(file);
outputStream.flush();
outputStream.close();
}