-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
它没有出现,你正在运行相同的代码,因为路径必须包含'/ logs /'或'\ logs \'。 –
'carbonelllogs'你缺少一个分隔符... – Eugene
userHome最后缺少“\” – Guilherme