2017-11-05 21:37:50
Properties:Properties
class represents a persisted set of properties. Properties
can be saved in a stream or loaded from a stream. Each key and its corresponding value in the property list is a string.
Properties is an attribute collection class that is a collection class that can be combined with an IO stream.
The properties class can be stored in a stream or loaded from a stream, which is a subclass of Hashtable, or a subclass of map.
* Construction Method
* Common Methods
~ Properties as the use of the map collection
public class Main {public static void Main (string[] args) { //No generics, not generic-class Properties prop = new properties (); c3/>//add element prop.put ("1", "Hello"); Prop.put ("2", "World"); Prop.put ("3", "!"); Traversal set set<object> set = Prop.keyset (); For (object K:set) { object val = Prop.get (k); System.out.println (k + "---" +val);}}}
~ Special Features of properties
- Public Object setProperty (String key,string value)
- public string GetProperty (string key)
- Public set<string> Stringpropertynames ()
public class Main {public static void Main (string[] args) { //No generics, not generic-class Properties prop = new properties (); c3/>//add element prop.setproperty ("1", "Hello"); Prop.setproperty ("2", "World"); Prop.setproperty ("3", "!"); Traversal set set<string> set = Prop.stringpropertynames (); for (string k:set) { string val = Prop.getproperty (k); System.out.println (k + "---" +val);}}}
~ Combination of properties and IO streams
- public void load (Reader reader): The data in the file is read into the Properties collection, and the data in the file must be in the form of a key-value pair.
- public void Store (Writer writer,string Comments): Stores the data in the collection into a file.
No generics, not generic-class Properties prop = new properties (); add element Prop.setproperty ("1", "Hello"); Prop.setproperty ("2", "World"); Prop.setproperty ("3", "!"); Writer w = new FileWriter ("E:/test.txt"); Prop.store (W, "HelloWorld");
#helloworld #sun Nov 22:06:16 CST 20171=hello2=world3=\!
Properties prop = new properties (); Reader r = new FileReader ("E:/test.txt"); Prop.load (r); R.close ();
Java IO stream-properties