Reputation: 77
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
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