📜  Java.util.Properties类

📅  最后修改于: 2020-11-14 06:21:10             🧑  作者: Mango


介绍

java.util.Properties类是代表一组持久属性的类.Properties可以保存到流中或从流中加载。以下是有关Properties的重点-

  • 属性列表中的每个键及其对应的值都是一个字符串。

  • 一个属性列表可以包含另一个属性列表作为其“默认值”,如果在原始属性列表中找不到该属性键,则搜索第二个属性列表。

  • 此类是线程安全的;多个线程可以共享一个Properties对象,而无需外部同步。

类声明

以下是java.util.Properties类的声明-

public class Properties
   extends Hashtable

领域

以下是java.util.Properties类的字段-

保护的属性默认值-这是属性列表,其中包含此属性列表中未找到的任何键的默认值。

类的构造函数

Sr.No. Constructor & Description
1

Properties()

This constructs creates an empty property list with no default values.

2

Properties(Properties defaults)

This constructs creates an empty property list with the specified defaults.

类方法

Sr.No. Method & Description
1 String getProperty(String key)

This method searches for the property with the specified key in this property list.

2 String getProperty(String key, String defaultValue)

This method searches for the property with the specified key in this property list.

3 void list(PrintStream out)

This method prints this property list out to the specified output stream.

4 void list(PrintWriter out)

This method prints this property list out to the specified output stream.

5 void load(InputStream inStream)

This method reads a property list (key and element pairs) from the input byte stream.

6 void load(Reader reader)

This method reads a property list (key and element pairs) from the input character stream in a simple line-oriented format.

7 void loadFromXML(InputStream in)

This method loads all of the properties represented by the XML document on the specified input stream into this properties table.

8 Enumeration propertyNames()

This method returns an enumeration of all the keys in this property list, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

9 void save(OutputStream out, String comments)

This method reads a.

10 Object setProperty(String key, String value)

This method calls the Hashtable method put.

11 void store(OutputStream out, String comments)

The method writes this property list (key and element pairs) in this Properties table to the output stream in a format suitable for loading into a Properties table using the load(InputStream) method.

12 void store(Writer writer, String comments)

The method writes this property list (key and element pairs) in this Properties table to the output character stream in a format suitable for using the load(Reader) method.

13 void storeToXML(OutputStream os, String comment)

This method emits an XML document representing all of the properties contained in this table.

14 void storeToXML(OutputStream os, String comment, String encoding)

This method emits an XML document representing all of the properties contained in this table, using the specified encoding.

15 Set stringPropertyNames()

This method returns a set of keys in this property list where the key and its corresponding value are strings, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

方法继承

此类从以下类继承方法-

  • java.util.Hashtable
  • java.util.Object