1.配置文件test.properties:

test_123=admin

注:value 可用单引号,双引号,不用引号修饰

2.工具类PropertiesUtil:

package com.......test;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertiesUtil {

    private static final String PROP_FILE = "test.properties";

    private static Properties properties;

    static {
properties = new Properties();
try {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(PROP_FILE);
BufferedReader bf = new BufferedReader(new InputStreamReader(is, "UTF-8"));//解决读取properties文件中产生中文乱码的问题
assert (is != null);
properties.load(bf); } catch (IOException e) {
throw new RuntimeException("读取" + PROP_FILE + "配置文件异常", e);
}
} public static String getValue(String key) {
return properties.getProperty(key);
}
}

3.测试

    @Test
public void test() {
String keyWord = "test_123";
String value = PropertiesUtil.getValue(keyWord);
System.out.println("value = " + value);
}

最新文章

  1. Javascript之自定义事件
  2. JQuery easyui Datagrid 分页事件
  3. 关于Unity3d粒子系统的小发现(天堂3技能释放)
  4. 使用Trello实现敏捷项目管理
  5. plsql无法连接64位oracle数据库的解决方法(图文解说)
  6. XML 命名空间(XML Namespaces)
  7. Internship
  8. Qt 学习之路 :事件
  9. 关于bootstrap--表单(下拉<select>、输入框<input>、文本域<textare>复选框<checkbox>和单选按钮<radio>)
  10. webapi文档
  11. UpdatePanel局部刷新用法
  12. MongoDB中的映射,限制记录和记录拼排序 文档的插入查询更新删除操作
  13. newinstance和new的区别
  14. Android为TV端助力 自定义view中findViewById为空的解决办法
  15. Maven学习笔记-04-Eclipse下maven项目在Tomcat7和Jetty6中部署调试
  16. Some untracked working tree files would be overwritten by checkout. Please move or remove them before you can checkout. View them
  17. CMD命令搜索有某文本文件的内容
  18. cocos游戏网址
  19. 阅读《Android 从入门到精通》(9)——多项选择
  20. POJ 3164 Sunscreen (挑战程序设计竞赛的练习题)

热门文章

  1. [NOIP2009] $Hankson$ 的趣味题 (数论,gcd)
  2. 推荐个PMP的内容,广州有需要的朋友可以参考看看
  3. Codeforces 403D: Beautiful Pairs of Numbers(DP)
  4. hdu 4183(网络流)
  5. LeetCode OJ--Best Time to Buy and Sell Stock III
  6. AC日记——拍照 洛谷 P3410
  7. 天梯赛 - L2-002 链表去重
  8. HDU 5046 Airport【DLX重复覆盖】
  9. Codeforces 622C Not Equal on a Segment 【线段树 Or DP】
  10. 咦?Oracle归档文件存哪了?