【发布时间】:2017-05-15 16:21:52
【问题描述】:
我从 Horstmann book(Volume2) 复制了代码示例,但不明白为什么它不起作用。你能帮助我吗?我试图删除 IOException,但它引发了另一个问题
package streams;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
public class Hello {
public static void main(String[] args) throws IOException
{
String contents = new String(Files.readAllBytes(Paths.get("text.txt")), StandardCharsets.UTF_8);
List<String> words = Arrays.asList(contents.split("\\PL+"));
long count = 0;
for(String w : words)
{
if (w.length() > 12) count++;
}
System.out.println(count);
count = words.stream().filter(w -> w.length() > 12).count();
System.out.println(count);
count = words.parallelStream().filter(w -> w.length() > 12).count();
System.out.println(count);
}
}
【问题讨论】:
-
请记住,最好将错误消息发布为代码格式的文本,而不是图像。
标签: java exception stream classnotfoundexception