• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

read a .txt file from classpath

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to read a .txt file from classpath containing values like this,

key = value
spaced key = spaced value

I have to capture the key and value.
I was intending to capture each line and use split or StringTokenizer to look for '=' to determine the key and value.

But on reading the file from classpath I get an InputStream. Is there any way to read each line in a file using InputStream?
Could someone provide a code snippet to the problem?

I could have used BufferedReader.readLine() if the file was in the working directory but the file is in the classpath and I have not found a way yet to read the file from the classpath and not obtain InputStream.
Can any one suggest how to obtain a Reader while reading a file from classpath?

Thanks in advance.
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most of the Stream and Reader/Writer classes allow wrapping of various other types.InputStreamReader is the magic glue necessary to convert from a byte stream to a character reader. BufferedReader gives you buffering for performance and readLine().
 
reply
    Bookmark Topic Watch Topic
  • New Topic