Here you can find the source of readAndConsume(String filePath, Consumer
static void readAndConsume(String filePath, Consumer<String> consumer) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.function.Consumer; import java.util.stream.Stream; public class Main { static void readAndConsume(String filePath, Consumer<String> consumer) throws IOException { Stream<String> lines = null; lines = Files.lines(Paths.get(filePath)); lines.forEach(consumer);/*from www .j a v a2 s . c o m*/ } }