JAVA Program to Replace Content of File

JAVA Program to Replace Content of File:


/* REPLACE OTHER WITH THE*/
import java.io.*;
import java.lang.*;
class file6
{
 public static void main(String args[])
 {
  BufferedReader br=null;
  File f1=new File(args[0]);
  try
  {
   br= new BufferedReader(new FileReader(f1));

   String line="";
   while((line=br.readLine())!=null)
   {
       if(line.contains("other"))
       line=line.replace("other","the");
       System.out.println(line);
   }
  }
  catch(Exception e){}
  finally
  {
       try
       {
           br.close();
       }
       catch(Exception e){}
  }
 }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

five × 4 =