簡體   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