import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.ibatis.io.Resources;
public class MybatisPropertiesUtil {
/**
* 根据Key读取全局配置文件的value
*
* @param key
* @return
*/
public static String getValueByKey(String file ,String key) {
Properties props = new Properties();
InputStream in = null;
try {
in = Resources.getResourceAsStream(file);
props.load(in);
return props.getProperty(key);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return "";
}
测试: 两个地方配置文件获取的方式