Java 8读取文件+流

时间:2017-06-07 08:26:57

标签: java java-8

我想使用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

1 个答案:

答案 0 :(得分:3)

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

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

应该是

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

最可能的解释是您已经在某个时刻修复了代码,但尚未成功重新部署代码。

相关问题