Assuming that the text file is in the jar itself, then don't grab it as a File, since technically, these don't exist in jar files, but rather get it as a resource.
e.g.,
package foo;
import java.io.InputStream;
import java.util.Scanner;
public class TestResource {
public static void main(String[] args) {
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
String resourceName = "foo/movies.txt"; // path relative to classloader
InputStream inStream = classLoader.getResourceAsStream(resourceName);
Scanner scanner = new Scanner(inStream);
while (scanner.hasNextLine()) {
System.out.println(scanner.nextLine());
}
if (scanner != null) {
scanner.close();
}
}
}
the contents of the jar file are:
C:\Users\hovercraft\Jar files>jar tf TestResource.jar
META-INF/MANIFEST.MF
foo/TestResource.class
foo/TestResource.java
foo/movies.txt