BufferedReader Class lines() method in Java with Examples Last Updated : 28 Jan, 2021 Comments Improve Suggest changes Like Article Like 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.txtThe 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. Comment More infoAdvertise with us Next Article BufferedReader Class lines() method in Java with Examples Z zack_aayush Follow Improve Article Tags : Java Technical Scripter Technical Scripter 2020 Java-BufferReader Practice Tags : Java Similar Reads BufferedReader close() method in Java with Examples The close() method of BufferedReader class in Java is used to close the stream and release all the system resources associated with the stream operations. Syntax: public void close() throws IOException Parameters: This method does not accept any parameter. Return value: This method does not return a 2 min read BufferedReader mark() method in Java with Examples The mark() method of BufferedReader class in Java is used to mark the current position in the buffer reader stream. The reset() method of the same BufferedReader class is also called subsequently, after the mark() method is called. The reset() method fixes the position at the last marked position so 3 min read BufferedReader reset() method in Java with Examples The reset() method of BufferedReader class in Java is used to fix or mark the position at the last marked position so that the same byte can be read again. Syntax: public void reset() throws IOException Overrides: It overrides the reset() method of Reader class. Parameters: The method does not accep 3 min read BufferedReader markSupported() method in Java with Examples The markSupported() method of BufferedReader class in Java is used to verify whether the stream supports the mark() method or not. It returns the boolean value true if the stream supports mark() otherwise it returns false. Syntax: public boolean markSupported() Overrides: It overrides the markSuppor 2 min read BufferedInputStream skip(long) method in Java with Examples The skip(long) method of BufferedInputStream class in Java is used to skip n bytes of data from the buffered input stream. The number of bytes skipped is stored and returned as long type. The termination condition involves either of the two: Either reading into a byte array until n-bytes are covered 2 min read Like