Anjana
Anjana

Reputation: 77

How to add input file when creating jar file

For my Java application, I use some input files inside src folder. But after I create the jar file and use it, it gives an error saying cannot find the file. How to add an input file when creating jar file in NetBeans?

Upvotes: 0

Views: 504

Answers (1)

Eng.Fouad
Eng.Fouad

Reputation: 117675

You need to use getResourceAsStream(String name), to get a stream to the file:

InputStream is = MyClass.class.getResourceAsStream("fileName");

This will return an input stream to the file fileName which is located inside a directory that MyClass.class is in.

Upvotes: 1

Related Questions