If you want to read a file content using java, following code sample will help you to achieve this purpose.I have further describe the steps which help you to understand what this code does

  1. You need to create an object from Buffered Reader class.
  2. Specify the file location which you need to read.
  3. If file has some content, you are reading the file until it becomes null.
sample code of buffer reader class
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FilterReader;
import java.io.IOException;

public class RD {
public static void main(String[] args) {
BufferedReader reader;
try {
reader = new BufferedReader(new FileReader(
"/home/AA/IdeaProjects/Microsoft1/out/production/Microsoft1/HelloWorld.txt"));
String line = reader.readLine();
while (line != null) {
System.out.println(line);
// read next line
line = reader.readLine();
}
reader.close();
}
catch (IOException e) {
e.printStackTrace();
}
}


}

Output

--

--