in java 8 , there are a new Class
java.util.stream.Stream
A stream represents a sequence of elements and supports different kind of operations to perform computations upon those elements
to Read more about it :
Here an Example :
import java.nio.charset.StandardCharsets;import java.nio.file.Files;import java.nio.file.Paths;import java.util.stream.Stream;public Class ReadFile{ public static String readFile(String filePath) { StringBuilder stringBuilder = new StringBuilder(); String ls = System.getProperty("line.separator"); try { try (Stream<String> lines = Files.lines(Paths.get(filePath), StandardCharsets.UTF_8)) { for (String line : (Iterable<String>) lines::iterator) { stringBuilder.append(line); stringBuilder.append(ls); } } } catch (Exception e) { e.printStackTrace(); } return stringBuilder.toString(); }}