使用javautilProperties类的load()方法
示例
InputStream in = new BufferedInputStream(new FileInputStream(name));
Properties p = new Properties();
pload(in);
使用javautilResourceBundle类的getBundle()方法
示例
ResourceBundle rb = ResourceBundlegetBundle(name LocalegetDefault());
使用javautilPropertyResourceBundle类的构造函数
示例
InputStream in = new BufferedInputStream(new FileInputStream(name));
ResourceBundle rb = new PropertyResourceBundle(in);
使用class变量的getResourceAsStream()方法
示例
InputStream in = JPropertiesclassgetResourceAsStream(name);
Properties p = new Properties();
pload(in);
使用classgetClassLoader()所得到的javalangClassLoader的getResourceAsStream()方法
示例
InputStream in = JPropertiesclassgetClassLoader()getResourceAsStream(name);
Properties p = new Properties();
pload(in);
使用javalangClassLoader类的getSystemResourceAsStream()静态方法
示例
InputStream in = ClassLoadergetSystemResourceAsStream(name);
Properties p = new Properties();
pload(in);
补充
Servlet中可以使用javaxservletServletContext的getResourceAsStream()方法
示例
InputStream in = contextgetResourceAsStream(path);
Properties p = new Properties();
pload(in);