import java.io.BufferedReader; import java.io.File; // Import the File class import java.io.FileNotFoundException; // Import this class to handle errors import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; // Import the Scanner class to read text files public class ReadFileToTest { public ArrayList readBufferedFile(String pTestFile) { // Declaring a string and initializing it with // path of file present on the system ArrayList arrayList = new ArrayList(); String path = pTestFile; // Try block to check for exceptions try (BufferedReader br = new BufferedReader(new FileReader(path))) { // Declaring a new string String str; // It holds true till there is content in file while ((str = br.readLine()) != null) { //put into a list: arrayList.add(str); // Printing the file data // System.out.println(str); } } // Catch block to handle the exceptions catch (IOException e) { // Display pop up message if exceptionn occurs System.out.println( "Error while reading a file."); } return arrayList; } }