Today read the Java properties of this east, usually at work, busy pinch.
Basic properties
1) Load (InputStream instream)
This method can load a property list into the Properties class object from the file input stream corresponding to the. Properties property file. as in the following code:
Newnew fileinputstream ("a.properties");p ro.load (in); In.close ();
GetProperty (String key)
SetProperty (String key,string value)
Store (OutputStream out, String comments)
This method saves the property list of the properties class object to the output stream . as in the following code:
New FileOutputStream (file, True);p Ro.store (ofile, "Comment"); Comment can generate comments Ofile.close ();
Publicclass propertytest {
public static void Main (string[] args) throws FileNotFoundException, IOException {
// TODO auto-generated Method Stub
Properties pro=New properties ();
FileInputStream f=New fileinputstream ("config.properties");
Pro.load (f);
//Set<string> stringpropertynames ()
Returns the set of keys in this property list, where the key and its corresponding value are strings, and if a key with the same name is not found in the main attribute list, the different keys in the default attribute list are also included.
Iterator<string> s=pro.stringpropertynames (). Iterator ();
while (S.hasnext ()) {
String Key=s.next ();
System. out . println (key +""+pro.getproperty (key));
}
F.close ();
The Save properties file is written to the output stream.
FileOutputStream ofile=New fileoutputstream ("b.properties",true );//indicates that the file can be appended.
Pro.setproperty ("Phone", "10086");
Pro.store (ofile,"The new Properties");//Generate a review
Ofile.close ();
}
Java Read Properities file