package com.tsinghua.getDataBaseConn;

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

public class GetProperty {

// 方法一:通过java.util.ResourceBundle读取资源属性文件
public static String getPropertyByName(String path, String name) {
String result = "";

try {
// 方法一:通过java.util.ResourceBundle读取资源属性文件
result = java.util.ResourceBundle.getBundle(path).getString(name);
System.out.println("name:" + result);
} catch (Exception e) {
System.out.println("getPropertyByName2 error:" + name);
}
return result;
}

// 方法二:通过类加载目录getClassLoader()加载属性文件
public static String getPropertyByName2(String path, String name) {
String result = "";

// 方法二:通过类加载目录getClassLoader()加载属性文件
InputStream in = GetProperty.class.getClassLoader()
.getResourceAsStream(path);
// InputStream in =
// this.getClass().getClassLoader().getResourceAsStream("mailServer.properties");

// 注:Object.class.getResourceAsStream在action中调用报错,在普通java工程中可用
// InputStream in =
// Object.class.getResourceAsStream("/mailServer.properties");
Properties prop = new Properties();
try {
prop.load(in);
result = prop.getProperty(name).trim();
System.out.println("name:" + result);
} catch (IOException e) {
System.out.println("读取配置文件出错");
e.printStackTrace();
}
return result;
}

}

最新文章

  1. android AsynTask处理返回数据和AsynTask使用get,post请求
  2. StarUML license key
  3. [LintCode] Longest Common Prefix 最长共同前缀
  4. JAVA--继承
  5. elk系列6之tcp模块的使用
  6. Html5 Egret游戏开发 成语大挑战(三)开始界面
  7. HTML5 Canvas rect()和strokeRect() 的区别
  8. ubuntu下firefox无法看bilibili解决方案
  9. mysql参数,蛮全的
  10. mysql 模块使用
  11. ExtJS4.2 Ext.grid.panel Store更改后刷新表格
  12. TypeError: document.getELementById is not a function
  13. Named function expressions demystified
  14. cocos2dx - android环境配置及编译
  15. 对于python这门课程的一些想法、计划、期望
  16. Luogu P5284 [十二省联考2019]字符串问题
  17. Vue(一)创建第一个Vue程序
  18. GitLab上传项目到新的分支
  19. odoo开发笔记 -- 升级模块 提示外部ID找不到
  20. mxnet安装及NDArray初体验

热门文章

  1. MySQL 根据身份证查找年龄段
  2. ldo的一些参数理解
  3. C#封装的一个JSON操作类
  4. Python中super()和__init__()方法
  5. .net SMTP 发送邮件
  6. FastAdmin env.sample 的用法
  7. 使用Navicat for Oracle新建表空间、用户及权限赋予 (转)
  8. 从汇编的角度看待变量类型与sizeof的机制
  9. dubbo相关的知识点总结
  10. bean对grub4dos做出的巨大贡献总结