0

I have a web application I came accross

InputStream iStream= Thread.currentThread().getContextClassLoader().getResourceAsStream("Test.Properties");

I am trying to understand what difference will it make if I write

Properties p = new Properties();
p.load(new BufferedReader(new FileReader("Test.properties")))

Can any one let me know how these two approaches are different?

A.Kumar
  • 43
  • 6

1 Answers1

0

If I understand you correctly then the difference is that the method getResourceAsStream() will look ok your classspath for the properties file.

The Filereader can read a file from anywhere in your file system, as long as you have the right to the path obviously.

Edit: It will use the Thread’s own class loader however as long as you don’t share any resources among other threads you’ll be fine either way.

I personally like the getResourceAsStream method because it allows me to simply throw files into a folder in my maven project e.g. /src/main/resources and I can simply retrieve no matter how my application is going to be packaged.

Walter
  • 21
  • 1
  • 8