JAVA讀取本地配置文件實例


import java.io.InputStream;
import java.util.Properties;

public class FileProperties extends Properties{
    public FileProperties(){}
    public FileProperties(String s)
    {
        try
        {
            InputStream inputStream = getClass().getResourceAsStream(s);
            load(inputStream);
            inputStream.close();
        }catch (Exception e)
        {
            System.err.println("Exception in FileProperties(String): "
                    + e.toString()
                    + " for filename="
                    + s);
        }
    }
    public FileProperties(Properties properties) {
        super(properties);
    }
    public static String getMyProperty(String name){
        FileProperties fp = new FileProperties("/cms.properties");
        if ( fp != null ) {
            return fp.getProperty(name);
        } else {
            return null;
        }
    }
}

 屬性配置文件cms.properties格式為:

#Socket_TIM_Z = 0 47 17 * * ?
Socket_TIM_J = 0 0 4 * * ?
Socket_TIM_ZZH = 2 * * ? * *

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM