http://www.open-open.com/lib/view/open1400721838050.html
1 1。使用java.util.Properties类的load()方法 2 示例: InputStream in = lnew BufferedInputStream(new FileInputStream(name)); 3 Properties p = new Properties(); 4 p.load(in); 5 6 2。使用java.util.ResourceBundle类的getBundle()方法 7 示例: ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault()); 8 9 3。使用java.util.PropertyResourceBundle类的构造函数 10 示例: InputStream in = new BufferedInputStream(new FileInputStream(name)); 11 ResourceBundle rb = new PropertyResourceBundle(in); 12 13 4。使用class变量的getResourceAsStream()方法 14 示例: InputStream in = JProperties.class.getResourceAsStream(name); 15 Properties p = new Properties(); 16 p.load(in); 17 18 5。使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法 19 示例: InputStream in = JProperties.class.getClassLoader().getResourceAsStream(name); 20 Properties p = new Properties(); 21 p.load(in); 22 23 6。使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法 24 示例: InputStream in = ClassLoader.getSystemResourceAsStream(name); 25 Properties p = new Properties(); 26 p.load(in); 27 28 补充 29 30 Servlet中可以使用javax.servlet.ServletContext的getResourceAsStream()方法 31 示例:InputStream in = context.getResourceAsStream(path); 32 Properties p = new Properties(); 33 p.load(in);