1.使用java.util.Properties類的load()方法
示例:
Java代碼
InputStream in = lnew BufferedInputStream(new FileInputStream(name));
Properties p = new Properties();
p.load(in);
2.使用java.util.ResourceBundle類的getBundle()方法
示例:
Java代碼
ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault());
3.使用java.util.PropertyResourceBundle類的構造函數
示例:
Java代碼
InputStream in = new BufferedInputStream(new FileInputStream(name));
ResourceBundle rb = new PropertyResourceBundle(in);
4.使用class變量的getResourceAsStream()方法
示例:
Java代碼
InputStream in = JProperties.class.getResourceAsStream(name);
Properties p = new Properties();
p.load(in);
5.使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法
示例:
Java代碼
InputStream in = JProperties.class.getClassLoader().getResourceAsStream(name);
Properties p = new Properties();
p.load(in);
6.使用java.lang.ClassLoader類的getSystemResourceAsStream()靜態方法
示例:
Java代碼
InputStream in = ClassLoader.getSystemResourceAsStream(name);
Properties p = new Properties();
p.load(in);
7.使用apache的PropertiesConfiguration類
示例:
Java代碼
Configuration config = new PropertiesConfiguration("test.properties");
config.getProperty(key);