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();
}

posted @ 2014-07-30 16:59  江湖小谢*VIP  阅读(178)  评论(0编辑  收藏  举报