1.创建一个测试用的.properties文件
2.获取 的两种方法
//第一种获取方法
public static void main(String[] args) throws IOException {
//获取单个properties
Properties properties = new Properties();
InputStream in =null;
in = Testo1.class.getClassLoader().getResourceAsStream("Test.properties");
properties.load(in);
in.close();
//赋值
properties.setProperty("url.name","bbb");
//取值
String property = properties.getProperty("url.name");
System.out.println(property);
}
//第二种获取方法
@Test
public void getProperties() throws IOException {
//设置时区
Locale locale = new Locale("zh","cn");
ResourceBundle resource = ResourceBundle.getBundle("Test",locale,Testo1.class.getClassLoader());
//取值
String value = resource.getString("url.name");
System.out.println(value);
System.out.println("时区=="+resource.getLocale());
}
区别 :
使用Properties 来获取的情况下不能设置locale,ResourceBundle可以设置Locale
使用Properties来获取的情况下可以通过setProperty(属性名,值)进行赋值,而ResourceBundle没有赋值的方法
3.输出