0

I mainly followed this thread:
How do you add files to a jar using Netbeans 6.5? I have a class named Card then needs to load a file and return the name of the InputStream.
This is the code to obtain the input:

public String getFilename()
{
    String result= "" + seed + "-" + value + ".png";
    return result;
}
public InputStream getInputStream()
{
    InputStream result;
    result= Card.class.getClassLoader().getResourceAsStream(getFilename());
    return result;
}

The filename is correct, all the files are in the src folder of the project.
If I try to run it with Netbeans 7.2 it works.But if I build the project and move the jar from it's original position, run it, it doesn't work anymore.It doesn't load the files(result is null).
What could the problem be?

Community
  • 1
  • 1
Ramy Al Zuhouri
  • 21,580
  • 26
  • 105
  • 187

3 Answers3

1

Try this:

result= Card.class.getResourceAsStream("/"+getFilename());
Gilberto Torrezan
  • 5,113
  • 4
  • 31
  • 50
0

I would move all the files into their own package "resources".

String result= "/resources/" + seed + "-" + value + ".png";

(This may not fix the problem but it is the recommended solution from various sites when handling resources. I know that this does work for eclipse IDE)

Colton
  • 645
  • 4
  • 24
0

The problem was that it didn't find a library, I had to move all the dist folder in order to make it work.

Ramy Al Zuhouri
  • 21,580
  • 26
  • 105
  • 187