/*
* Function Description: reads the value corresponding to a key of the resource file.
* @ Param key refers to the corresponding key in the resource file; for example, com.cn. Test
* @ Param file_path: the path of the resource file, which can be an absolute path. For example,/test. properties.
*/
Private Static string readproperties (string key, string file_path ){
Properties props = new properties ();
Inputstream instream = Main. Class. getresourceasstream (file_path );
Try {
Props. Load (instream );
Instream. Close ();
} Catch (ioexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Return props. getproperty (key );
}
/*
* Function Description: write data to the resource file. Note that the resource file must be placed in the SRC and directory.
* @ Param key refers to the corresponding key in the resource file; for example, com.cn. Test
* @ Param value the value corresponding to the key in the resource file;
* @ Param file_name Note: The resource file must be placed in the SRC and directory. For example, test. properties.
*/
Public static void SaveFile (string key, string value, string file_name ){
String filepath = Main. Class. getresource ("/"). getpath () + file_name;
File file = new file (filepath );
Inputstream FCM = NULL;
Outputstream outputfile = NULL;
Properties props = new properties ();
Try {
FCM = new fileinputstream (filepath );
// Read the attribute list (key and element pair) from the input stream)
Props. Load (FS );
Outputfile = new fileoutputstream (File );
Props. setproperty (Key, value );
// Write the attribute list (key and element pair) in the properties table to the output stream.
Props. Store (outputfile, "Update'" + value + "'value ");
Outputfile. Close ();
} Catch (exception e ){
E. printstacktrace ();
}
}