2017-06-07 40 views
-1

我想读通过使用Java 8个流 我有这样一段代码文件里逐行:的Java 8读取文件+流

@RequestMapping(value = { "/viewlog" }, method = { RequestMethod.GET }) 
public String viewLoad(final ModelMap model) throws IOException { 
    System.out.println ("reading file from userHome -> " + userHome); 
    String content = null; 
    try { 
     content = new String(Files.readAllBytes(Paths.get(userHome + "/logs/nicinc/nicinc.log"))); 
    } catch (Exception e) { 
     System.out.println ("Exception e -> " + e.getMessage()); 
    } finally { 
     System.out.println ("content -> " + content); 
    } 
    //System.out.println ("content -> " + content); 
    return serverContextPath + SYSTEM_LOG_VIEW; 
} 

但是,这是我从控制台了,它真的对我来说没有意义:

65630 [http-nio-8080-exec-4] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [/nicinc] threw exception 
java.nio.file.NoSuchFileException: C:\Users\carbonelllogs\nicinc\nicinc.log 
+0

它没有出现,你正在运行相同的代码,因为路径必须包含'/ logs /'或'\ logs \'。 –

+3

'carbonelllogs'你缺少一个分隔符... – Eugene

+0

userHome最后缺少“\” – Guilherme

回答

3

您正在查找的文件缺少路径分隔符。

C:\Users\carbonelllogs\nicinc\nicinc.log 

应该

C:\Users\carbonell\logs\nicinc\nicinc.log 

最可能的解释是,你必须固定在某一点上的代码,但没有成功地重新部署它。