Package COM.XIAN.JDBC;
Import Java.io.BufferedInputStream;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Java.io.InputStream;
Import Java.util.Iterator;
Import java.util.Properties;
Import Javax.servlet.jsp.jstl.sql.Result;
public class GetProperties {
public static void Main (string[] args) throws IOException {
OracleConnection ora=new OracleConnection ();
Result result=ora.runselectsql ("Select Key from Properties");
Result result2=ora.runselectsql ("Select value from Properties");
Properties prop = new properties ();//Property Collection Object
FileOutputStream Fis=null; Output file
try {
FIS =new fileoutputstream ("prop.properties");
} catch (Exception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}//Property File Stream
for (int i=0;i<result.getrowcount (); i++) {
System.out.println (Result.getrows () [I].values ());
System.out.println (Result2.getrows () [I].values ());
Write
Prop.setproperty (Result.getrows () [I].values (). ToString (), Result2.getrows () [I].values (). ToString ());
}
Prop.store (FIS, "The New properties File");
Fis.close ();
Read
InputStream in = new Bufferedinputstream (New FileInputStream ("Prop.properties"));
Prop.load (in); Load Property List
Iterator<string> it=prop.stringpropertynames (). Iterator ();
while (It.hasnext ()) {
String Key=it.next ();
System.out.println (key+ "=" +prop.getproperty (key));
}
In.close ();
}
}
This article is from the "Jia Xiaoxian" blog, make sure to keep this source http://hackerxian.blog.51cto.com/9240575/1626890
Java properties files are added from the database to the file