• Post Reply Bookmark Topic Watch Topic
  • New Topic

get properties as input stream  RSS feed

 
Mohammed Yousuff
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please explain this line of code.

as i do understand this line of code is loading a properties file as a input stream. However why they have use the classname ??


InputStream is = <class_NAME>.class.getClassLoader().getResourceAsStream(CONFIG_APP_FILE);
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this case you're loading a resource off the CLASSPATH. In order for Java to find CLASSPATH for you it needs to start with the class you are currently in and 'work its way up to find the CLASSPATH that the class is running in' (That's the non technical/Java explanation).

I know others will have more accurate explanations than this and perhaps some alternative suggestions on how to get that resource, so pile on in people!
 
Rodrigo Tomita
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mohammed Yousuff:
However why they have use the classname ??


The objective is to get a reference to the class loader (and then access the classpath as Martijn explained). You can either do:



or use the class name:



More info in:the Class object javadoc.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!