Skip to main content
added 6 characters in body; edited title
Source Link
Natan Streppel
  • 5.9k
  • 6
  • 39
  • 43

Java - How to load a File within a Jar that is not relative to the Class its loaded from

I am trying to load a file that is within a jar file. I try to get the file to load in a BufferedReader. For example: BufferedReader br = new BufferedReader(new FileReader(fileName));

BufferedReader br = new BufferedReader(new FileReader(fileName)); 

where fileName is my string from the root of the Jar file: something like this "resources/text.txt"

I am having a hard time finding out how to make this happen. Obviously FileReader will not work since it reads from the file system.

Anyone that can help me out?

Java - How to load a File within a Jar that is not relative to the Class its loaded from

I am trying to load a file that is within a jar file. I try to get the file to load in a BufferedReader. For example: BufferedReader br = new BufferedReader(new FileReader(fileName));

where fileName is my string from the root of the Jar file: something like this "resources/text.txt"

I am having a hard time finding out how to make this happen. Obviously FileReader will not work since it reads from the file system.

Anyone that can help me out?

How to load a File within a Jar that is not relative to the Class its loaded from

I am trying to load a file that is within a jar file. I try to get the file to load in a BufferedReader. For example:

BufferedReader br = new BufferedReader(new FileReader(fileName)); 

where fileName is my string from the root of the Jar file: something like this "resources/text.txt"

I am having a hard time finding out how to make this happen. Obviously FileReader will not work since it reads from the file system.

Anyone that can help me out?

Source Link
c-pid
  • 122
  • 1
  • 9

Java - How to load a File within a Jar that is not relative to the Class its loaded from

I am trying to load a file that is within a jar file. I try to get the file to load in a BufferedReader. For example: BufferedReader br = new BufferedReader(new FileReader(fileName));

where fileName is my string from the root of the Jar file: something like this "resources/text.txt"

I am having a hard time finding out how to make this happen. Obviously FileReader will not work since it reads from the file system.

Anyone that can help me out?