`
y806839048
  • 浏览: 1090637 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

读取配置文件工具

阅读更多
package com.lj.util; 
 
import java.io.IOException; 
import java.io.InputStream; 
import java.util.Properties; 
 
public class Configuration { 
    
    //采用单例模式 
    private static final Configuration configuration = new Configuration(); 
 
    private Configuration(){} 
    
    public synchronized static Configuration getInstance(){ 
        return configuration; 
    } 
    
    public String read(String properties,String key){ 
        //读取配置文件 
        InputStream in = this.getClass().getClassLoader().getResourceAsStream(properties); 
        Properties p = new Properties(); 
        try { 
            p.load(in); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 
        
        //取得配置文件中的值 
        return p.getProperty(key); 
    } 




config.properties


1.#配置索引路径 
2.indexPath=d:/LuceneIndex/LuceneTest02/ 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics