It's somewhat unclear to me what you're trying to do. But if the file is within a jar file, FileReader
isn't going to work anyway - you don't have a file as far as the operating system is concerned. You should just use getResourceAsStream
, and then wrap the InputStream
in an InputStreamReader
. That way you can also specify a character encoding - even when I am using a file, I use FileInputStream
and InputStreamReader
for that reason.
So you want something like:
try (Reader reader = new InputStreamReader(
ClassA.class.getResourceAsStream("foo.txt"),
StandardCharsets.UF_8)) { // Or whichever encoding is appropriate
// Read from the reader
}