首页 > 代码库 > SpringMvc 文件上传
SpringMvc 文件上传
public
void importExcel(MultipartFile file, HttpServletRequest request) throws FileNotFoundException, IOException {
//tomcat下路径
String path = request.getSession().getServletContext().getRealPath("upload");
//上传文件名称
String fileName = file.getOriginalFilename();
System.out.println("****************开始***************");
File targetFile = new File(path, fileName);
if(!targetFile.exists()){
targetFile.mkdirs();
}
//保存
try {
file.transferTo(targetFile);
System.out.println("****************上传结束***************");
} catch (Exception e) {
e.printStackTrace();
}