import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ReadTextFile { public static void main(String[] args) { // Specify the path to your text file, e.g. path/to/your/text/file.txt String filePath = "words.txt"; // Create a File object to represent the text file File filename = new File(filePath); try { // Create a Scanner to read from the file Scanner scanner = new Scanner(filename); // Read and print each line from the file while (scanner.hasNextLine()) { String line = scanner.nextLine(); System.out.println(line); } // Close the scanner to release resources scanner.close(); } catch (FileNotFoundException e) { // Handle the case where the file is not found System.err.println("File not found: " + filePath); e.printStackTrace(); } } }