BufferedReader Class lines() method in Java with Examples Read Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue Report 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. Syntax: 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: Java // Java program to demonstrate the continuous scanning // by BufferedReader.lines() method and return the stream // of lines that contains the specific word import java.io.*; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.*; import java.util.Arrays; import java.util.List; import java.util.stream.Stream; class GFG { public static void main(String[] args) { FileReader f= new FileReader("location of the file"); BufferedReader b = new BufferedReader(f); // taking the stream as a string Stream<String> i = b.lines(); i.filter(line -> line.contains("Hello")).findAny().ifPresent(System.out::println); // filter the stream that line contains Hello is // preset output b.close(); f.close(); } } Output: Hello this is the first line. Hello this is the second line. Feeling lost in the vast world of Backend Development? It's time for a change! Join our Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule. What We Offer: Comprehensive Course Expert Guidance for Efficient Learning Hands-on Experience with Real-world Projects Proven Track Record with 100,000+ Successful Geeks Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore. Last Updated : 28 Jan, 2021 Like Article Save Article Previous Java Program to Illustrate the Usage of Floating Next Remove One Array From Another Array in Java Share your thoughts in the comments Add Your Comment Please Login to comment...