....
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!");
        }
    }
...

解决方案 »

  1.   

    建议改用 XML 作配置文件, 有一个简单的包 jconfig 可以帮助你www.jconfig.org简单的例子:
    http://www.jconfig.org/jConfig/Main/portal/wiki?page=GettingStarted
      

  2.   

    建议改用 XML 作配置文件, 有一个简单的包 jconfig 可以帮助你www.jconfig.org简单的例子:
    http://www.jconfig.org/jConfig/Main/portal/wiki?page=GettingStarted
      

  3.   

    <?xml version="1.0" encoding="iso-8859-1" ?>
    <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");
        }
    }