0

The it seems that the program can't see the file. The text file is within the same package as the program. Am I missing somethings?

 package trycatch;
 import java.util.*;
 import java.nio.file.Paths;

 public class ReadingFromeAFile {
 public static void main (String args []) {
    try(Scanner scanner = new Scanner (Paths.get("read.txt"))){


        while (scanner.hasNextLine()){
            String row = scanner.nextLine();
            System.out.println(row);
        }
    }


        catch(Exception e){
            System.out.println("Error: " + e.getMessage());
        }

}
}
  • Does this answer your question? [How to really read text file from classpath in Java](https://stackoverflow.com/questions/1464291/how-to-really-read-text-file-from-classpath-in-java) – Sharon Ben Asher Apr 21 '20 at 11:27
  • Does this answer your question? [Reading txt file from a specific package Java](https://stackoverflow.com/questions/4361338/reading-txt-file-from-a-specific-package-java) – Giancarlo Romeo Apr 21 '20 at 11:31

0 Answers0