1. Features
The Properties class represents a persistent set of attributes that can be stored in a stream or loaded from a stream, enabling memory and file intersection
Properties inherit the Hashtable<object,object> class and can use methods such as Add (), AddAll (), but they only support
A string type of key and value, so methods such as setproperty () are defined inside the properties to ensure type safety. In its associated text
Each property inside the piece is represented by this: Key=value.
2. Methods
Load (InputStream in) |
Reading a list of attributes from an input stream |
SetProperty (string key, String value) |
Call Hashtable's put () method |
GetProperty (String key) |
Call Hashtable's Get () method |
Store (OutputStream out, String comments) |
Write the property list to the output stream |
List (OutputStream out) |
Output a property list to a specified output stream |
3. Use
Code
public class Propertiesdemo {
public static void Main (string[] args) throws IOException {
File File = new file ("C:properties.txt");
Properties P = new properties ();
Add Property key value
P.setproperty ("A", "97");
P.setproperty ("B", "98");
P.setproperty ("C", "99");
P.setproperty ("D", "100");
P.setproperty ("B", "100");
Write to specified file
P.store (new FileOutputStream (file), null);
Reads the property key value from the specified file
P.load (new FileInputStream (file));
In the console output
P.list (System.out);
}
}
Operation Result:---listing properties--b=100a=97d=100c=99 at the same time, in the C-disk directory to generate the corresponding
Properties.txt file.
Technology sharing: www.kaige123.com
This article from the "11247808" blog, reproduced please contact the author!
Properties of common Java classes