This is my jsp code for saving back the data to .properties file after editing. i used 2 Linked properties as one LinkedProperties pro is to get the data from the path and the other one to get attribute (eg: id, name, age, gender etc.) from default .properties file so that i don't have to hard code everything in every page:
String path = request.getParameter("path");
System.out.println(path);
File dir = new File(path);
FileInputStream in = new FileInputStream(dir);
LinkedProperties pro = new LinkedProperties();
pro.load(in);
Enumeration em = pro.keys();
//default file
File d_dir = new File("C:/workspace_indigo/Configuration/WebContent/default.properties");
LinkedProperties d_pro = new LinkedProperties();
FileInputStream d_in = new FileInputStream(d_dir);
d_pro.load(d_in);
Enumeration ems = d_pro.keys();
//save to file.
if (request.getParameter("id") != null) {
while (ems.hasMoreElements()){
String str = (String) ems.nextElement();
pro.setProperty(str, request.getParameter(str));
}
pro.store(new FileOutputStream(path), null);%>
<script type="text/javascript">
alert("Change Saved sucessfully.");
//window.location.href="List_of_Repo.jsp";
</script>
<% }
d_pro.clear();
d_in.close();
pro.clear();
in.close();
I can save the file back into the corresponding .properties file but the problem is i cannot delete the file after editing is save. The error message is the file is still in used.
help me.