Check out example codes for "java how to read a text file". It will help you in understanding the concepts better.

Code Example 1

import;  // Import the File class
import;  // Import this class to handle errors
import java.util.Scanner; // Import the Scanner class to read text files

public class ReadFile {
  public static void main(String[] args) {
    try {
      File myObj = new File("filename.txt");
      Scanner myReader = new Scanner(myObj);
      while (myReader.hasNextLine()) {
        String data = myReader.nextLine();
    } catch (FileNotFoundException e) {
      System.out.println("An error occurred.");

Code Example 2

import java.util.Scanner;

class Scratch{
    public static void main(String[] args) throws FileNotFoundException {
        Scanner input = new Scanner(new File("filename"));;       //returns next String
        input.nextLine();   //returns next Line
        input.nextBoolean();//returns next Boolean
        input.nextInt();    //returns next Int
        input.nextDouble(); //returns next double

Learn ReactJs, React Native from