以下是我写的重置值的函数,谢谢
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();
} }
解决方案 »
- Hibernate里什么时候用session.beginTransaction();呢?
- 关于事务提交问题,急
- 我没改什么啊,怎么突然报错了呢。工作无法继续了,任务期限就要到了,请大哥大姐们帮帮忙啊。
- was向mq里面发消息为什么说:javax.naming.NameNotFoundException: Name jms not found in context "java:comp/env".
- 关于JDOM的问题
- 怎么根据id、父id自动遍历出树形结构xml?
- 本人裸体跪求ncsow.jar包
- 怎样才能获得当前数据库的连接数啊?
- 哪有eclipse3.0中得jbossplugin下载啊?
- 请有经验的人给出在struts下写访问控制的方法
- oracle数据库连接时出异常,求指教
- 关于excel数据导入到sql数据库的题,求热心大神指导一下!
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());改成这样