以下是我写的重置值的函数,谢谢
public void setPara(String fileName,String key,String value) {
Properties prop = new Properties();
try{
ClassLoader cl = this.getClass().getClassLoader();
InputStream is = cl.getResourceAsStream(fileName);
prop.load(is);
if(is != null)
is.close();
}catch(Exception e){
System.out.println(e + "file " + fileName + " not found");
}
prop.setProperty(key,value);
FileOutputStream fos;
try {
fos = new FileOutputStream(fileName);
try {
prop.store(fos, null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
public void setPara(String fileName,String key,String value) {
Properties prop = new Properties();
try{
ClassLoader cl = this.getClass().getClassLoader();
InputStream is = cl.getResourceAsStream(fileName);
prop.load(is);
if(is != null)
is.close();
}catch(Exception e){
System.out.println(e + "file " + fileName + " not found");
}
prop.setProperty(key,value);
FileOutputStream fos;
try {
fos = new FileOutputStream(fileName);
try {
prop.store(fos, null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
public String getPara(String fileName,String field){
Properties prop = new Properties();
try{
ClassLoader cl = this.getClass().getClassLoader();
InputStream is = cl.getResourceAsStream(fileName);
prop.load(is);
if(is != null)
is.close();
}catch(Exception e){
System.out.println(e + "file " + fileName + " not found");
}
return prop.getProperty(field);
}
public void setPara(String fileName,String key,String value) {
Properties prop = new Properties();
try{
ClassLoader cl = this.getClass().getClassLoader();
InputStream is = cl.getResourceAsStream(fileName);
prop.load(is);
if(is != null)
is.close();
}catch(Exception e){
System.out.println(e + "file " + fileName + " not found");
}
prop.setProperty(key,value);
FileOutputStream fos;
try {
fos = new FileOutputStream(fileName);
try {
prop.store(fos,null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
public static void main(String [] args){
ReadPro readpro = new ReadPro();
String ex = readpro.getPara("config.properties", "ExceptionPiont");
System.out.println("++++++++++++++++++++++"+ex);
readpro.setPara("config.properties","ExceptionPiont" , "23");
String exchange = readpro.getPara("config.properties", "ExceptionPiont");
System.out.println("++++++++++++++++++++++"+exchange); }
}
要把那个set方法的
FileOutputStream fos = new FileOutputStream(cl.getResource(fileName).toURI().getPath());改成这样