java 解析 properties-使用 Properties-可以指定配置文件路径

#mq
xdr.mq.url=tcp://192.168.100.15:61618;

import java.io.IOException;
import java.util.Properties;


public class Test {

String conf = "log4j.properties";
private static final String homepath = PropertiesHelper.getHomePath();
   
    Properties rb = new Properties();
    public  String url= rb.getProperty("xdr.mq.url");
   
public static void main(String[] args) throws FileNotFoundException, IOException{
Test t = new Test();
//进行初始化
if(t.url==null){
t.rb.load(new FileInputStream(homepath + File.separator + "log4j.properties"));
t.url= t.rb.getProperty("xdr.mq.url");
}
t.rb.load(new FileInputStream(homepath + File.separator + "log4j.properties"));
   
System.out.println("url:"+t.rb.getProperty("xdr.mq.url"));
}
}

你可能感兴趣的:(java,properties)