package com.wise;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;
public class TestProperties {
//the properties file 's name is test.properties,its filePath is the same as javaFile
//and the content of the properties file is
// "i_am_key=i_am_value"
public static void main(String[] args) {
readPropertiesMethod1("/test.properties");
}
public static void readPropertiesMethod1(String filename){
Properties pro = new Properties();
try {
InputStream is = TestProperties.class.getResourceAsStream("/test.properties");
pro.load(is);
String value = pro.getProperty("i_am_key");
System.out.println(value);
} catch (IOException e) {
}
}
public static void readPropertiesMethod2(String filename){
ResourceBundle rb = ResourceBundle.getBundle("test",Locale.getDefault());
String value = rb.getString("i_am_key");
System.out.println(value);
}
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。