我想使用Java 8 Stream逐行读取文件 我有这段代码:
@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 :(得分:3)
您要查找的文件缺少路径分隔符。
C:\Users\carbonelllogs\nicinc\nicinc.log
应该是
C:\Users\carbonell\logs\nicinc\nicinc.log
最可能的解释是您已经在某个时刻修复了代码,但尚未成功重新部署代码。