java的properties文件从数据库添加到文件

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();//属性集合对象

FileOutputStream fis=null;         //输出文件

try {

fis =new FileOutputStream("prop.properties");

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}//属性文件流

for(int i=0;i<result.getRowCount();i++){

System.out.println(result.getRows()[i].values());

System.out.println(result2.getRows()[i].values());

//写入

prop.setProperty(result.getRows()[i].values().toString(),result2.getRows()[i].values().toString());

}

// prop.store(fis, "The New properties file");

fis.close();

 

 

//读取

InputStream in = new BufferedInputStream (new FileInputStream("prop.properties"));

prop.load(in);     ///加载属性列表

Iterator<String> it=prop.stringPropertyNames().iterator();

while(it.hasNext()){

String key=it.next();

System.out.println(key+"="+prop.getProperty(key));

}

in.close();

}

}


你可能感兴趣的:(数据库,import,package,public,result)