properties配置文件中动态存取数据
import java.io.IOException;
import java.util.Properties;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.File;
/**
* <p>Title:在indexerConfig.properties配置文件中动态存取数据 </p>
*
* <p>Description: 可以动态存取数据,key所对应的值为value</p>
*
* @version 1.0
*/
public class DbTextIndexerConfig {
private static String nubmerStrBefore;
private static String nubmerStrNow;
public static boolean LoadConfig(int key,int value){
Properties properties = new Properties();
FileInputStream fin = null;
FileOutputStream fos = null;
try{
fin = new FileInputStream("indexerConfig.properties");
properties.load(fin);
fos = new FileOutputStream("indexerConfig.properties");
nubmerStrBefore = properties.getProperty(Integer.toString(value));
nubmerStrNow =(String) properties.setProperty(Integer.toString(key),Integer.toString(value));
properties.store(fos,Integer.toString(key));
}catch(Exception e){
e.printStackTrace();
return false;
}finally{
if (fin!=null){
try {
fin.close();
} catch (IOException ex) {
}
}
}
return true;
}
public static String getNubmerStrBefore() {
return nubmerStrBefore;
}
public static String getNubmerStrNow() {
return nubmerStrNow;
}
/**
* 测试
* @param args String[]
*/
public static void main(String args[]){
DbTextIndexerConfig.LoadConfig(402,4000);
}
}