coding made simple with some delicious cake

How to read a properties file in Java

In this tutorial we will demonstrate how to read a properties file in Java from your classpath. Property files are generally loaded on application startup, to help initialise the application. Property files commonly contains information relating to external service endpoints, connection pool configurations etc …

How to read a properties file in Java

In this example we will be using the following properties file, which is normally located in the /main/resources directory of your project.

conf.properties File

1

2

pool.size=3

blog.url=http://codingwithcake.com

The following code example demonstrates how to load the property file using the ClassLoader. The ClassLoader will load the property file if it is present on the classpath. If the property file is not on the classpath then no file will be read and your InputStream will be null.