I am trying to read a text file from inside a .jar file and use a Scanner on it. The text file movies.txt is located in the src directory together with the java file in my IDE. When I build the jar file, both the class file and the text file are in the root directory.
InputStream file = this.getClass().getResourceAsStream("/movies.txt");
Scanner scanner = new Scanner(file);
This does not seem to locate the text file. What am I doing wrong here?