您的位置:首页 > 编程语言 > Java开发

java动态加载配置文件

2014-03-19 17:50 573 查看
1、首先在包www.teamtop.utils中新建config.properties文件。配置两个键值对,如图:

auth.confirm=http://121.8.243.66:81/confirm.jsp?accountId=%s&loginCode=%s
excel.path=/logicServer/src/excel.asd


2、编写解析文件

package www.teamtop.com;

import java.util.ResourceBundle;

public class ConfigUtil {

private static final ResourceBundle config = ResourceBundle.getBundle("www.teamtop.utils.config");

public static String getAuthConfirm() {
return config.getString("auth.confirm");
}

public static String getExcelPath() {
return config.getString("excel.path");
}
}

3、调用

package www.teamtop.com;

import org.junit.Test;

public class TestPro {

@Test
public void testPro(){
String path = ConfigUtil.getExcelPath();
System.out.println(path);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: