Read From File

Read File

If you want to read content from a file, you can import java.io.File; and import java.util.Scanner; and easily read the content.

Read File

import java.io.File; 
import java.util.Scanner;

public class FileWork {
    public static void main(String[] args) {
        try {
            File myObj = new File("myfile.txt");
            Scanner reader = new Scanner(myObj);
            while (reader.hasNextLine()) {
                String mydata = reader.nextLine();
                System.out.println(mydata);
            }
            reader.close();
        } catch (Exception e) {
            System.out.println("Error "+e.getMessage());
        }
    }
}