Read and write functions such as the following:
<textarea cols="50" rows="15" name="code" class="java">import java.io.fileinputstream;import java.io.fileoutputstream;import java.util.properties;public Properties Loadconfig (context context, String file) {Properties Properties = new Properties (); try {fileinputstream s = new fileinputs Tream (file);p roperties.load (s);} catch (Exception e) {e.printstacktrace ();} return properties;} public void Saveconfig (context context, String file, properties properties) {try {fileoutputstream s = new Fileoutputstrea m (file, False);p Roperties.store (S, "");} catch (Exception e) {e.printstacktrace ();}}</textarea>
Orz, did you find anything? Yes, these two functions have nothing to do with Android.
So they can be used in other standard Java programs as well.
In Android, it is better to read and write from a pure string, parse it yourself, or use XML to save the configuration.
Properties appear simpler and more intuitive, due to the need for a lot of code, and XML operation is far less convenient than the properties
Usage such as the following:
Write configuration:
<textarea cols="50" rows="15" name="code" class="java">Properties prop = new properties ();p rop.put ("Prop1", "abc");p rop.put ("Prop2", 1);p rop.put ("Prop3", 3.14); Saveconfig (This, "/sdcard/config.dat", prop);</textarea>
Read configuration:
<textarea cols="50" rows="15" name="code" class="java">Properties prop = Loadconfig (this, "/sdcard/config.dat"); String Prop1 = Prop.get ("Prop1");</textarea>
Note: You can also use the context Openfileinput and Openfileoutput methods to read and write files
At this point the file will be saved under/data/data/package_name/files and managed by the system
When you read and write to a file using this method, you cannot specify a detailed path for the file.
Android under the Properties save program configuration