熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

java 讀取properties 文件

2022-06-13   來源: Java核心技術 

  使用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);


From:http://tw.wingwit.com/Article/program/Java/hx/201311/25724.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.