--------------------------------------Signature
Recently, the company needs to do a function: In the Web project, using Web pages to dynamically modify the connection parameters in JDBC. In addition to directly changing the value of the bean in the spring container, there is a modification of the connection parameter key value pairs in the jdbc.properties. So how do you get to the value of replacing a pair of key-value pairs with a key?
--------------------------------------Code
String Password = request.getparameter ("password");
String path = Request.getsession (). Getservletcontext (). Getrealpath ("/") + "web-inf\\classes\\cfg\\properties\\ Jdbc.properties ";
InputStream in = null;
OutputStream out = null;
Try {
Properties prop = new properties ();
in = new FileInputStream (path);
Prop.load (in);//Deposit input stream to prop key value pair
Prop.setproperty ("Jdbc.password", password);//change or save key value pair out
= new FileOutputStream (path);
Prop.store (out, null); Put the prop key value pair into out output stream
} catch (Exception e) {
e.printstacktrace ();
} finally {
in.close ();
Out.close ();
}