....
private static Properties pConfig = new Properties();
function()
{
FileInputStream in = null;
try
{
in = new FileInputStream("config.properties");
pConfig.load(in);
in.close();
}
catch (Exception ex)
{
ex.printStackTrace ();
}
} public static String getPropByName(String name) throws Exception
{
if (pConfig.containsKey(name))
{
return characterChang(pConfig.getProperty(name));
}
else
{
throw new Exception("not found " + name + " properties!");
}
}
...
private static Properties pConfig = new Properties();
function()
{
FileInputStream in = null;
try
{
in = new FileInputStream("config.properties");
pConfig.load(in);
in.close();
}
catch (Exception ex)
{
ex.printStackTrace ();
}
} public static String getPropByName(String name) throws Exception
{
if (pConfig.containsKey(name))
{
return characterChang(pConfig.getProperty(name));
}
else
{
throw new Exception("not found " + name + " properties!");
}
}
...
http://www.jconfig.org/jConfig/Main/portal/wiki?page=GettingStarted
http://www.jconfig.org/jConfig/Main/portal/wiki?page=GettingStarted
<properties>
<variables>
<variable name="my.path" value="/home/foo/data"/>
</variables>
<category name="general">
<property name="upload_dir" value="${my.path}/data"/>
<property name="NewsCounter" value="10"/>
<property name="showNews" value="true"/>
<property name="MyProp" value="Hello world"/>
</category>
<category name="JDBC">
<property name="URL" value="jdbc:mysql://localhost/iportal"/>
<property name="DRIVER" value="org.gjt.mm.mysql.Driver"/>
<property name="PWD" value="pwd"/>
<property name="USER" value="user"/>
</category>
</properties>
===============================================================
String myProp = configuration.getProperty("MyProp");
System.out.println("MyProp:"+myProp);
String jdbcUser = configuration.getProperty("USER",null,"JDBC");
System.out.println("jdbcUser:"+jdbcUser);
int newsCounter = configuration.getIntProperty("NewsCounter",-1);
if ( newsCounter == 10 ) {
System.out.println("We have found the correct value");
}
boolean showNews = configuration.getBooleanProperty("showNews",false);
if ( showNews ) {
System.out.println("We have to show the news");
}
}