The Files.lines().forEach()
method doesn't allow the break
. What's the optimal way to read lines in Java 8 in chunks and break when needed?
Update 1: Example for exception.
public class Main {
public static void main(String[] args) {
try(IntStream s = IntStream.range(0, 5);){
s.forEach(i -> validate(i));
}catch(Exception ex){
System.out.println("Hello World!");
}
}
static void validate(int s){
if(s > 1){
//throw new Exception(); ?
}
System.out.println(s);
} }