title: I need to read a xml file and change the id of each tag to id+tagname
body: <p>I need to read a file and find and replace some text in the same file without closing reader.</p>
  
  <p>Suggest any easy ways...</p>
  
  <p>Iam reading the file as follows. How can I write it to the same file.</p>
  
  <pre><code>private static void readFile(String path) throws IOException {
          makeFolderStructure(path);
          for (String xmlNameString : xmlFileNamesList) {
              FileReader xmlFile = new FileReader(
                      path + "\\xml\\" + xmlNameString + ".xml");
              BufferedReader br = new BufferedReader(xmlFile);
              try {
                  String line = br.readLine();
                  while (line != null) {
                      if (line.contains("&lt;") &amp;&amp; line.indexOf(" ") != -1) {
                          String tagName = line.substring(line.indexOf("&lt;") + 1,
                                  line.indexOf(" "));
                          if (line.indexOf("id") != -1) {
                              Pattern p = Pattern.compile("\"([^\"]*)\"");
                              Matcher m = p.matcher(line);
                              while (m.find()) {
                                  String tagId = (m.group(1));
                                  System.out.println(tagId+"_"+tagName);
                              }
                          }
                      }
                      line = br.readLine();
                  }
              } finally {
                  br.close();
              }
          }
      }
  </code></pre>