在Scala应用程序中,我尝试使用java nio try-with-resource构造从文件中读取行.
Scala版本2.11.8
Java版本1.8
try(Stream<String> stream = Files.lines(Paths.get("somefile.txt"))){
stream.forEach(System.out::println); // will do business process here
}catch (IOException e) {
e.printStackTrace(); // will handle failure case here
}
Run Code Online (Sandbox Code Playgroud)
但是编译器会抛出错误,例如
找不到:值流
◾尝试没有捕获或者最终等同于将其主体放入块中; 没有例外处理.
不确定是什么问题.我是使用Java NIO的新手,所以非常感谢任何帮助.