You can get the content of a MultipartFile
by using the getBytes
method and you can write to the file using Files.newOutputStream()
:
public void write(MultipartFile file, Path dir) {
Path filepath = Paths.get(dir.toString(), file.getOriginalFilename());
try (OutputStream os = Files.newOutputStream(filepath)) {
os.write(file.getBytes());
}
}
You can also use the transferTo method:
public void multipartFileToFile(
MultipartFile multipart,
Path dir
) throws IOException {
Path filepath = Paths.get(dir.toString(), multipart.getOriginalFilename());
multipart.transferTo(filepath);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…