开发者社区> 问答> 正文

关于Spring mvc 向服务器上传文件报错问题 ?报错

Spring mvc在向服务器上传的文件的时候报错 显示系统找不到指定的路径,应该要怎么修改

展开
收起
爱吃鱼的程序员 2020-06-24 14:08:51 560 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    错误粘出来看看,可能原因有很多

    代码是这个

    @RequestMapping("/updateExcel")publicStringupdateExcel(HttpServletRequestrequest,HttpServletResponseresponse){System.out.println("导入考生信息");CommonsMultipartResolvermultipartResolver=newCommonsMultipartResolver(request.getSession().getServletContext());StringfileName=null;StringstroreName=null;if(multipartResolver.isMultipart(request)){MultipartHttpServletRequestmultiRequest=(MultipartHttpServletRequest)request;Iterator<String>iter=multiRequest.getFileNames();while(iter.hasNext()){//由CommonsMultipartFile继承而来,拥有上面的方法.MultipartFilefile=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("."));

    //FilesavePathFile=newFile(///imgAddr/imgLocation
    //getPathname("yyyyMM",newDate()));
    //if(!savePathFile.exists()){
    //savePathFile.mkdirs();
    }
    Stringpath=fileName+"/"+stroreName;

    System.out.println(fileName+"/"+stroreName);FilelocalFile=newFile(path);System.out.println(path);try{file.transferTo(localFile);}catch(IllegalStateExceptione){e.printStackTrace();//thrownewServiceException(e);}catch(IOExceptione){e.printStackTrace();//thrownewServiceException(e);}}}returnfileName;}报错的提示导入考生信息

    test.xlsx/1438844285782.xlsx
    test.xlsx/1438844285782.xlsx
    java.io.FileNotFoundException:test.xlsx\1438844285782.xlsx(系统找不到指定的路径。)

    Stringpath=fileName+"/"+stroreName;

    中间的/换成\试试.

    2020-06-24 14:09:07
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
如何运维千台以上游戏云服务器 立即下载
网站/服务器取证 实践与挑战 立即下载
ECS快储存加密技术 立即下载