If I want to read from "Words.txt" which is in the same package as the class, how would I do this? Doing simply Scanner = new Scanner(new File("Words.txt"));
returns an error.
InputStream is = MyClass.class.getResourceAsStream("Words.txt");
...
Scanner = new Scanner(new File("/path/to/Words.txt"));
The argument in the File() constructor, Is the path relative to the system your VM is running on, it s doesn't depend on the classe's package.
If you your words.txt is a resource packaged with your war you can see here : Load resource from anywhere in classpath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With