How to replace multiple occurences of a string in a text file with a variable entered by the user and save all to a new file?
<pre><code> public static void main(String args[])
     {
     try
         {
         File file = new File("input.txt");
         BufferedReader reader = new BufferedReader(new FileReader(file));
         String line = "000000", oldtext = "414141";
         while((line = reader.readLine()) != null)
             {
             oldtext += line + "\r\n";
         }
         reader.close();
         // replace a word in a file
         //String newtext = oldtext.replaceAll("drink", "Love");

         //To replace a line in a file
         String newtext = oldtext.replaceAll("This is test string 20000", "blah blah blah");

         FileWriter writer = new FileWriter("input.txt");
         writer.write(newtext);writer.close();
     }
     catch (IOException ioe)
         {
         ioe.printStackTrace();
     }
 }
</code></pre>

<p>}</p>
