java - Reading txt file from jar fails but reading image works -


i have issue has been bothering me days... checked similar questions couldn't find solution.

i use netbeans ide. build project jar file i.e "clock.jar" contains "clock" named folder in images, text file , project classes found. following code creating image icon works

return new imageicon(getclass().getresource("/clock/button_close.png")); 

but following code reading text file fails

inputstream name = getclass().getresourceasstream("/clock/input.txt"); bufferedreader reader = new bufferedreader(new inputstreamreader(name)); 

as may have guessed nullpointer exception thrown meaning couln't locate file.

but how come image icon constructed (by passing url returned getresource) txt file cannot found (by passing input stream getresourceasstream).

thanks in advance, answer ( mean :) )

jar -tvf clock.jar 0 wed may 15 14:44:36 eest 2013 meta-inf/ 202 wed may 15 14:44:34 eest 2013 meta-inf/manifest.mf 0 wed may 15 14:44:36 eest 2013 clock/ 649 wed may 15 14:44:36 eest 2013 clock/clock$1$1.class 789 wed may 15 14:44:36 eest 2013 clock/clock$1.class 2026 wed may 15 14:44:36 eest 2013 clock/clock.class 709 wed may 15 14:44:36 eest 2013 clock/clockdialog$1.class 830 wed may 15 14:44:36 eest 2013 clock/clockdialog$2.class 750 wed may 15 14:44:36 eest 2013 clock/clockdialog$3.class 713 wed may 15 14:44:36 eest 2013 clock/clockdialog$4.class 741 wed may 15 14:44:36 eest 2013 clock/clockdialog$5.class 708 wed may 15 14:44:36 eest 2013 clock/clockdialog$6.class 1081 wed may 15 14:44:36 eest 2013 clock/clockdialog$7.class 981 wed may 15 14:44:36 eest 2013 clock/clockdialog$8.class 9640 wed may 15 14:44:36 eest 2013 clock/clockdialog.class 702 wed may 15 14:44:36 eest 2013 clock/clockframe$1.class 708 wed may 15 14:44:36 eest 2013 clock/clockframe$2.class 734 wed may 15 14:44:36 eest 2013 clock/clockframe$3.class 743 wed may 15 14:44:36 eest 2013 clock/clockframe$4.class 531 wed may 15 14:44:36 eest 2013 clock/clockframe$5.class 1046 wed may 15 14:44:36 eest 2013 clock/clockframe$6.class 9464 wed may 15 14:44:36 eest 2013 clock/clockframe.class 782 wed may 15 14:44:36 eest 2013 clock/errorreporter.class 1826 wed may 15 14:44:36 eest 2013 clock/iconbutton.class 2693 wed may 15 14:44:36 eest 2013 clock/messagepool.class 2824 wed may 15 14:44:36 eest 2013 clock/systeminfo.class 2212 wed may 15 14:44:36 eest 2013 clock/button_close.png 6540 wed may 15 14:44:36 eest 2013 clock/button_close_highlighted.png 5668 wed may 15 14:44:36 eest 2013 clock/input.txt 

looking @ source again closely, try..

url url = getclass().getresource("/clock/input.txt");  inputstream name = url.openstream();  

i recall getresourceasstream variant deals paths differently getresource - sure should work latter one.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -