- 我的属性文件中有一些插入的值。这会像,
键=值
- 我必须更新属性文件。更新时,正在检查密钥是否可用。如果键在那里,我需要删除键和值并重新写入。
- 任何人都可以给我代码以在再次更新/写入之前删除现有的键和值。
这是我要插入和更新的java代码:
if (action.equals("insert")) {
if (con != null) {
if (key == null) {
//session.setAttribute(username, con);
out.println("****Connected Successfully****");
String rootPath=request.getSession().getServletContext().getRealPath("/");
System.out.println(rootPath);
String propPath=rootPath+"/WEB-INF/";
PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter(propPath+"importedDB.properties", true)));
out1.println(cname+"=jdbc:oracle:thin:@"+host+":"+port+"/"+service+","+username+","+password);
out1.close();
} else {
out.println("*Connection name "+cname+" already exists. Please try with another name");
}
}
}
if (action.equals("update")) {
if (con != null) {
if (key == null) {
out.println(cname+" is not available.");
} else {
String rootPath=request.getSession().getServletContext().getRealPath("/");
System.out.println(rootPath);
String propPath=rootPath+"/WEB-INF/";
PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter(propPath+"importedDB.properties", true)));
out1.println(cname+"=jdbc:oracle:thin:@"+host+":"+port+"/"+service+","+username+","+password);
out1.close();
out.println("updated successfully");
}
}
}