How to read text file from jar

The next code works from eclipse IDE (run as java application) but is not works from jar:

     BufferedReader reader = new BufferedReader(new FileReader(new File("test.txt")));

and this one works properly from IDE and jar:

     BufferedReader reader = new BufferedReader(new
             InputStreamReader(getClass().getResourceAsStream("names.txt")));
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • RSS
  • Twitter
  • Yahoo! Bookmarks
  • Yahoo! Buzz
  • BlinkList
  • blogmarks
  • DZone
  • E-mail this story to a friend!
  • LinkaGoGo
  • Live
  • MisterWong
  • MisterWong.DE
  • Reddit
  • StumbleUpon
  • Technorati
  • ThisNext
  • Tumblr

Related posts:

  1. How to convert InputStream to BufferedReader
  2. GetResource().getPath() FileNotFoundException while running from jar

Leave a Reply


wordpress seo