FileNotFoundException

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

FileNotFoundException

Vladimir Nizamutdinov
Hello all! My plugin reads data from a text file, and I want to put
this file in jar archive together with binaries classes. I put this
file in the root of the archive, and read as BufferedReader br = new
BufferedReader(new FileReader("weights.txt"));
but still I get FileNotFoundException. How can i fix this error?
--
Best regards,
Nizamutdinov Vladimir

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: FileNotFoundException

Davíð Þór Bragason
Hi Vladimir,

I believe in a case like this you need to access the file as as "resource",
something like:

BufferedReader br = new BufferedReader(new InputStreamReader(
getClass().getClassLoader().getResourceAsStream("weights.txt")));

Regards,
David


On Sun, Aug 2, 2015 at 12:06 PM, Vladimir Nizamutdinov <[hidden email]
> wrote:

> Hello all! My plugin reads data from a text file, and I want to put
> this file in jar archive together with binaries classes. I put this
> file in the root of the archive, and read as BufferedReader br = new
> BufferedReader(new FileReader("weights.txt"));
> but still I get FileNotFoundException. How can i fix this error?
> --
> Best regards,
> Nizamutdinov Vladimir
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: FileNotFoundException

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by Vladimir Nizamutdinov
> On Aug 2, 2015, at 8:06 AM, Vladimir Nizamutdinov <[hidden email]> wrote:
>
> Hello all! My plugin reads data from a text file, and I want to put
> this file in jar archive together with binaries classes. I put this
> file in the root of the archive, and read as BufferedReader br = new
> BufferedReader(new FileReader("weights.txt"));
> but still I get FileNotFoundException. How can i fix this error?

The "JAR Resources Demo” plugin at

   http://imagej.nih.gov/ij/plugins/pcl-demo.html

demonstrates how to read text files, images, LUTs and macros from a jar file.

-wayne


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html