java regular expression in a file content
<p>How to use regular expressions in a file content. i am having group of files, i want to search a string in all the files and replace in all the files.</p>

<p>can anybody help me in this? the cose is below:</p>

<pre><code>package com.java.far;
import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ReplaceAll {

    public static void main(String[] args)throws IOException {

        Runtime r=Runtime.getRuntime();
        System.out.println(r.freeMemory());

        String path="D:\\JOBRELATED\\FAR";
        String files;
        File folder=new File(path);
        File[] listofFiles=folder.listFiles();
        for (int i = 0; i &lt; listofFiles.length; i++) {
            if (listofFiles[i].isFile()) {
                files=listofFiles[i].getName();
                if(files.endsWith("tex")){
                System.out.println(files);

                BufferedReader br=new BufferedReader(new FileReader("D:\\JOBRELATED\\FAR\\"+files));
                String line;
                while((line=br.readLine())!=null){
                Pattern p=Pattern.compile("Diamond in History and Research");
                Matcher m=p.matcher(line);
                int count=0;
                while (m.find()) {
                    count++;
                    //System.out.println(m.start() +"\t"+ count);
                    System.out.println(line);
                    m.replaceAll("abc");


                }
                }

            }
            }
        }


    }
}
</code></pre>
