Assume that the input stream is fetched from a file, and then reads one line of output at a time until the read is complete. With the BufferedReader ReadLine () in Java io, the "read a line as the name implies" implementation:
Import Java.io.bufferedreader;import Java.io.fileinputstream;import Java.io.inputstream;import Java.io.inputstreamreader;public class MainClass {public static void main (string[] args) {try {InputStream is = new Filein Putstream ("file.txt"); BufferedReader reader = new BufferedReader (new InputStreamReader (IS)); String str = Null;while (true) {str = Reader.readline (); if (str!=null) System.out.println (str); elsebreak;} Is.close ();} catch (Exception e) {e.printstacktrace ();}}}
File.txt File Contents:
12345
Code Run output:
12345
Java reads one line at a time from an input stream: Bufferedreader.readline ()