默认已经知道:MultipartFile 这个类一般是用来接受前台传过来的文件。
那transferTo方法有什么作用呢?
打开源码:
public void transferTo(File dest) throws IOException, IllegalStateException {
if (!this.isAvailable()) {
throw new IllegalStateException("File has already been moved - cannot be transferred again");
} else if (dest.exists() && !dest.delete()) {
throw new IOException("Destination file [" + dest.getAbsolutePath() + "] already exists and could not be deleted");
} else {
try {
this.fileItem.write(dest);
if (logger.isDebugEnabled()) {
String action = "transferred";
if (!this.fileItem.isInMemory()) {
action = this.isAvailable() ? "copied" : "moved";
}
logger.debug("Multipart file '" + this.getName() + "' with original filename [" + this.getOriginalFilename() + "], stored " + this.getStorageDescription() + ": " + action + " to [" + dest.getAbsolutePath() + "]");
}
} catch (FileUploadException var3) {
throw new IllegalStateException(var3.getMessage(), var3);
} catch (IOException | IllegalStateException var4) {
throw var4;
} catch (Exception var5) {
throw new IOException("File transfer failed", var5);
}
}
}
意思是说:把dest这个文件路径所指向的文件上传到对应的目录下。