package properties;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/***
* 通过java.util.Properties类来读取
* @author Administrator
*
*/
public class ClassLoderProperties {
//初始化创建Properties对象
private static Properties properties = new Properties();
//properties路径
private static String path = "/abc.properties";
//提前加载properties配置文件
static {
try {
// 方法一:使用ClassLoader加载properties配置文件生成对应的输入流
InputStream in = ClassLoderProperties.class.getClassLoader().getResourceAsStream(path);
// 方法二:使用InPutStream流读取properties文件
// BufferedReader in = new BufferedReader(new FileReader("E:/config.properties"));
// 使用properties对象加载输入流
properties.load(in);
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("properties文件加载报错");
e.printStackTrace();
}
}
public static String getKey(String key) {
return properties.getProperty(key);
}
}