Advertisement: RazorSQL
Query, update, navigate, and manage all databases from one database
client with ease using RazorSQL, a database query tool, SQL Editor,
database navigator, and administraton tool.
Download a free trial today!
Advertisement: EditRocket
The text editor for programmers with coding tools and support for over 20 languages. Download a free trial today!
import java.util.Locale;
import java.util.ResourceBundle;
public class PropertiesReader
{
private Locale locale = null;
private String propertiesFile = null;
private ResourceBundle resourceBundle = null;
public PropertiesReader (String propertiesFile, Locale locale)
{
this.setLocale (locale);
this.setPropertiesFile (propertiesFile);
this.setResourceBundle ( ResourceBundle.getBundle(this.getPropertiesFile(), this.getLocale()) );
}
public PropertiesReader (String propertiesFile)
{
this (propertiesFile, Locale.getDefault());
}
public PropertiesReader ()
{}
public void setLocale (Locale locale)
{
this.locale = locale;
}
public Locale getLocale ()
{
return this.locale;
}
public void setPropertiesFile (String propertiesFile)
{
this.propertiesFile = propertiesFile;
}
public String getPropertiesFile ()
{
return this.propertiesFile;
}
public void setResourceBundle (ResourceBundle resourceBundle)
{
this.resourceBundle = resourceBundle;
}
public ResourceBundle getResourceBundle ()
{
return this.resourceBundle;
}
public String getProperty (String propertyName)
{
String propertyValue = this.getResourceBundle().getString(propertyName);
return propertyValue;
}
public static void main (String[] args)
{
//create new PropertiesReader using a file called testfile.properties that must be located in the current directory
//testfile.properties must have a property named name in it for this example to work
//this example uses the default locale for the system [Locale.getDefault()]
PropertiesReader pr = new PropertiesReader("testfile");
String name = pr.getProperty ("name");
System.out.println (name);
}
}