The program runs well with getResource, but after made it into the jar file, it has FileNotFoundException
. It cannot find out test.conf.
My code is
URL url = getClass().getResource("test.conf");
File fin = new File(url.getPath());
FileInputStream fis = null;
try {
fis = new FileInputStream(fin);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
I think I can fix the problem by using getResourceAsStream. But I'm not sure how to change getResource to getResourceAsStream.
Your example suggests that your reading code already works on a FileInputStream. You should be able to make it work with the more general InputStream. This will allow you to just pass the result of getResourceStream() to your reading code, without having to worry about Files.
So:
Changes to: