English 中文(简体)
Java.util - Properties
  • 时间:2024-09-17

Java.util.Properties Class


Previous Page Next Page  

Introduction

The java.util.Properties class is a class which represents a persistent set of properties.The Properties can be saved to a stream or loaded from a stream.Following are the important points about Properties −

    Each key and its corresponding value in the property pst is a string.

    A property pst can contain another property pst as its defaults , this second property pst is searched if the property key is not found in the original property pst.

    This class is thread-safe; multiple threads can share a single Properties object without the need for external synchronization.

Class declaration

Following is the declaration for java.util.Properties class −

pubpc class Properties
   extends Hashtable<Object,Object>

Field

Following are the fields for java.util.Properties class −

protected Properties defaults − This is the property pst that contains default values for any keys not found in this property pst.

Class constructors

Sr.No. Constructor & Description
1

Properties()

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

2

Properties(Properties defaults)

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

Class methods

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

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

2 String getProperty(String key, String defaultValue)

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

3 void pst(PrintStream out)

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

4 void pst(PrintWriter out)

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

5 void load(InputStream inStream)

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

6 void load(Reader reader)

This method reads a property pst (key and element pairs) from the input character stream in a simple pne-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 pst, including distinct keys in the default property pst if a key of the same name has not already been found from the main properties pst.

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 pst (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 pst (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<String> stringPropertyNames()

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

Methods inherited

This class inherits methods from the following classes −

    java.util.Hashtable

    java.util.Object

Advertisements