繁体   English   中英

如何修复java.nio.file.NoSuchFileException:C:\\ Users \\ profilepics \\ default.jpg

[英]HOW TO FIX java.nio.file.NoSuchFileException: C:\Users\profilepics\default.jpg

我在glassfish服务器中出现错误。 说我的文件夹/文件不存在。 我复制并粘贴了此处说明的路径,并且图像在那里。 我正在显示从这里到我的JSP的图像。

    [2017-10-05T20:39:38.389+0800] [glassfish 4.1] [WARNING] [] 
    [javax.enterprise.web] [tid: _ThreadID=28 _ThreadName=http-listener-1(3)] 
    [timeMillis: 1507207178389] [levelValue: 900] [[
    StandardWrapperValve[spring]: Servlet.service() for servlet spring threw 
    exception
    java.nio.file.NoSuchFileException: C:\Users\Adminitrator-
    IT\Desktop\default.jpg
    at 
    sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
    at 
    sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
    at 
    sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
    at 
sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230)
    at java.nio.file.Files.newByteChannel(Files.java:317)
    at java.nio.file.Files.newByteChannel(Files.java:363)
    at 
java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:380)
    at java.nio.file.Files.newInputStream(Files.java:108)
    at java.nio.file.Files.copy(Files.java:2895)
    at com.project.controller.UploadController.readImage(UploadController.java:96)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)

我绝对是初学者。 我正在使用Spring和glassfish4。这是我在Controller中的代码,

 @RequestMapping(value = "/getavatar/{value}", method = RequestMethod.GET)
        public void readImage(HttpServletRequest request, HttpServletResponse response,@PathVariable String value)
                throws ServletException, IOException {
            //int cifid = authenticationFacade.getSessionData().getCifid(); 

            ServletContext sc = request.getServletContext();



            File image = new File(com.aimglobalinc.constants.AimConstants.AVATAR_FOLDER + value + "_avatar.jpg");

            if(!image.exists()){
                image = new File(com.aimglobalinc.constants.AimConstants.AVATAR_FOLDER + "default.jpg");
            } 

            String contentType = sc.getMimeType(image.getName());
            response.reset();
            response.setContentType(contentType);
            response.setHeader("Content-Length", String.valueOf(image.length()));
            Files.copy(image.toPath(), response.getOutputStream());
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM