繁体   English   中英

Java 8读取文件+流

[英]Java 8 Read File + Stream

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

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

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

应该

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

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

暂无
暂无

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

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