পৃষ্ঠাসমূহ

.

Search Your Article

Total Pageviews

Thursday, January 19, 2017

Java.util.Properties Class

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 list is a string.
  • A property list can contain another property list as its 'defaults', this second property list is searched if the property key is not found in the original property list.
  • 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:
public class Properties
   extends Hashtable<Object,Object>

Field

Following are the fields for java.util.Properties class:
  • protected Properties defaults -- This is the property list that contains default values for any keys not found in this property list.

Class constructors

S.N. 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.

Class methods

S.N. 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<String> 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.

Methods inherited

This class inherits methods from the following classes:
  • java.util.Hashtable
  • java.util.Object

No comments:

Post a Comment