Using FileReader to read a file inside JAR
807605Jul 18 2007 — edited Jul 18 2007I have the following code:
private void readFile(String type) {
BufferedReader in = null;
URL file = getClass().getResource("Hello.txt");
try {
in = new BufferedReader(new FileReader(file.getPath()));
} catch (FileNotFoundException ex) {
ex.printStackTrace();
System.out.println("Unable to open file.");
}
}
This works great within the compiler since the file is located within the pakage, however when I try to run the jar it does not work.
I need to figure out a way to keep the file location non-static and be able to read the file from within the JAR