title: How to replace a line in a text file using Java?
body: <p>I have a text file with various key value pairs separated with a '--'.
  Below is the code I have so far</p>
  
  <pre><code>        File file = new File("C:\\StateTestFile.txt");
          BufferedWriter out = new BufferedWriter(file.getAbsolutePath());
          BufferedReader br = new BufferedReader(new FileReader(file));
          String line;
          while ((line = br.readLine()) != null) {
             if(line.contains("content_style")) {
                 //Write to the line currently reading and save back to the file
             }
          }
          br.close();
  
          out.close();
  </code></pre>
  
  <p>What I would like to do is read this text file and replace the value of a specific line with something I specify. So id want to find the 'content_style' line and replace 'posh' with 'dirty'.</p>
  
  <p>How can I do this?</p>