Spring mvc在向服务器上传的文件的时候报错 显示系统找不到指定的路径,应该要怎么修改
错误粘出来看看,可能原因有很多
代码是这个
@RequestMapping("/updateExcel")
public String updateExcel(HttpServletRequest request,HttpServletResponse response){
System.out.println("导入考生信息");
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(
request.getSession().getServletContext());
String fileName = null;
String stroreName = null;
if (multipartResolver.isMultipart(request)) {
MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
Iterator<String> iter = multiRequest.getFileNames();
while (iter.hasNext()) {
// 由CommonsMultipartFile继承而来,拥有上面的方法.
MultipartFile file = multiRequest.getFile(iter.next());
if(file.getSize()>40*1024*1024){
return "overMaxSize";
}
if (file != null) {
fileName = file.getOriginalFilename();
stroreName = System.currentTimeMillis() + ""
+ fileName.substring(fileName.lastIndexOf("."));
// File savePathFile = new File( // /imgAddr/imgLocation
// getPathname("yyyyMM", new Date()));
// if (!savePathFile.exists()) {
// savePathFile.mkdirs();
}
String path = fileName + "/" + stroreName;
System.out.println( fileName + "/" + stroreName);
File localFile = new File(path);
System.out.println(path);
try {
file.transferTo(localFile);
} catch (IllegalStateException e) {
e.printStackTrace();
// throw new ServiceException(e);
} catch (IOException e) {
e.printStackTrace();
// throw new ServiceException(e);
}
}
}
return fileName;
}
报错的提示
导入考生信息
test.xlsx/1438844285782.xlsx
test.xlsx/1438844285782.xlsx
java.io.FileNotFoundException: test.xlsx\1438844285782.xlsx (系统找不到指定的路径。)
String path = fileName + "/" + stroreName;
中间的/换成\试试.