JAVA讀取屬性文件的幾種辦法總結。本站提示廣大學習愛好者:(JAVA讀取屬性文件的幾種辦法總結)文章只能為提供參考,不一定能成為您想要的結果。以下是JAVA讀取屬性文件的幾種辦法總結正文
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);