In java, there are many ways to read a text file. We can read text file either line-by-line or character-by-character. Here is the simplest program of reading a text file line-by-line in java.
To read a text file line-by-line in java we use BufferedReader. As BufferedReader cannot directly communicate with File, BufferedReader can only communicate with file via some Reader, so first we will create a FileReader object.
BufferedReader have readLine() method. Which reads next line and return as a string. When there is no next line (End of File) then readLine() return null value.
public class BufferedReaderLine
public static void main(String args) throws Exception
File f = new File("abc.txt"); // Any text file path
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String s = br.readLine();
while(s != null)
s = br.readLine();