Home > Java > How to load properties file using ResourceBundle

How to load properties file using ResourceBundle

As i promised on my preview post, here how to load properties file using  ResourceBundle, it took only 2 lines of code.

public class ResourceBundleReader {
public static void main(String[] args) {
//load properties file, remember NO .properties extension
ResourceBundle bundle = ResourceBundle.getBundle("config");
System.out.println(bundle.getString("test.address"));//load value
}
}

And here is my eclipse structure.

and my config.properties, only filled by one line,

test.address=https://namingexception.wordpress.com
Advertisements
Categories: Java
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: