BufferedReader Class lines() method in Java with Examples
BufferedReader.lines() is the method of the Java Buffered Reader Class in the Java Library which returns lines in terms of Stream and from this Buffered Reader class. With the help of the stream, there are a lot of methods that mimic the output according to our needs.
BufferedReader.lines() : Stream<String>
Parameters: This method does not take any kind of parameter.
Return: This method returns the stream of lines in terms of Stream and the Generic Type Change the stream into String.
Exception: IOException will be thrown when accessing the underlying BufferedReader which is wrapped in an UncheckedIOException.
Example: Find the line containing Hello as a word it will only work in a continuous scanning
- The directory contains one txt files named as GFG.txt
- The text File contains two lines:
Hello this is the first line. Hello this is the second line.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.