我想将上传的图像保存到Tomcat上部署的Spring 3 MVC应用程序中的特定文件夹中
我的问题是我无法将上传的图像文件保存到运行applciation的主机.
这是我尝试过的:
private void saveFile(MultipartFile multipartFile, int id) throws Exception {
String destination = "/images/" + id + "/" + multipartFile.getOriginalFilename();
File file = new File(destination);
multipartFile.transferTo(file);
}
Run Code Online (Sandbox Code Playgroud)
结果:FileNotFoundException - 是的,我确实想要创建这个文件!?!
我尝试使用context.getRealPath或getResources("destination"),但没有任何成功.
如何使用我的多部分文件的内容在我的应用程序的特定文件夹中创建新文件?