I'm joking with a java trying to program a game, I'm not going to define useless details, the program works, but it works only if I get it from the point where I developed it (Netbeans), but if I try to get it started Jar nothing, I read on the internet that to access files, such as images or txt files, you have to use the Class.class.getResourceAsStream (path), but the latter does not work from starting it from the jar, in fact or me From a NullPointerException or goes smooth, but does not load anything.
Disappeared I would explain the structure of my project and show you my code:
List build
-build
- classes
- mario
-all the package and the file example: crediti/ringraziamenti.txt
List dist
-dist
-jarFile
-mario
-all the package and the file example: crediti/ringraziamenti.txt
-meta inf...
List java
-src
-mario
- all the package and the file example: crediti/ringraziamenti.txt
my code is:
InputStream io =(getClass().getClassLoader().getResourceAsStream("mario/crediti/ringraziamenti.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(io));
String temp = "";
while((temp = br.readLine())== null){
System.out.println(""+temp);
}