background image

 

J2SE API

读取

Properties

文件六种方法

 

1。使用 Java.util.Properties 类的 load()方法

  示例:
InputStreamin=lnewBufferedInputStream(newFileInputStream(name));

  Propertiesp=newProperties();

  p.load(in);

  2。使用 java.util.ResourceBundle 类的 getBundle()方法

  示例:
ResourceBundlerb=ResourceBundle.getBundle(name,Locale.getDefault());

  3。使用 java.util.PropertyResourceBundle 类的构造函数

  示例:
InputStreamin=newBufferedInputStream(newFileInputStream(name));

  ResourceBundlerb=newPropertyResourceBundle(in);

  4。使用 class 变量的 getResourceAsStream()方法

  示例:InputStreamin=JProperties.class.getResourceAsStream(name);

  Propertiesp=newProperties();

  p.load(in);

  5。使用 class.getClassLoader()所得到的 java.lang.ClassLoader 的
getResourceAsStream()方法

  示例:
InputStreamin=JProperties.class.getClassLoader().getResourceAsStream(name
);

  Propertiesp=newProperties();

  p.load(in);