title: Delete key and value from properties file using java
body: <ul>
  <li>I have some inserted values in my properties file. which will be like,</li>
  </ul>
  
  <blockquote>
    <p>Key=Value</p>
  </blockquote>
  
  <ul>
  <li>I have to update the properties file. while updating, am checking whether the key is available. if key is there, i need to delete the key and value and have to write it again.</li>
  <li>Can anyone give me the code to delete the existing key and value before updating/writing it again.</li>
  </ul>
  
  <p>here is my java code to insert and update:</p>
  
  <pre><code> 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");
      }
    }
  }
  </code></pre>