小编Raj*_*r S的帖子

java try-with-resource不使用scala

在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的新手,所以非常感谢任何帮助.

java scala try-with-resources

11
推荐指数
1
解决办法
7209
查看次数

标签 统计

java ×1

scala ×1

try-with-resources ×1