Hello,
i have following .txt file
aaa<!--UserID-->aaa
aaa<!--app name-->aaa
aaa<!--Error-->aaa
aaa<!--LDAPGroup-->aaa
I want to replace <!--UserID-->,<!--app name-->,<!--Error-->,<!--LDAPGroup-->,so output should be
aaaRahulaaa
aaaMyAppaaa
aaaMyErroraaa
aaaMyLDAPaaa
I have written following code which replaces only last line aaa<!--LDAPGroup-->aaa
private
String getForm1(String app,String userId,String error,String ldapGrp){
String replaceStr="";
BufferedReader br;
try{
File file = new File("input.txt");
br = new BufferedReader(new FileReader(file));
String line="";
String oldText="";
String newText="";
while((line = br.readLine())!= null){
oldText += line + "\r\n";
}
br.close();
newText = oldText.replaceAll("<!--UserID-->",userId);
newText = oldText.replaceAll("<!--app name-->",app);
newText = oldText.replaceAll("<!--Error-->",error);
newText = oldText.replaceAll("<!--LDAPGroup-->",ldapGrp);
FileWriter writer = new FileWriter("input.txt");
writer.write(newText);
writer.close();
System.out.println("Done ...");
}catch(Exception e){
System.out.println("Exception :"+ e.toString());
}
return replaceStr;
}
Thank-You
Rahul Shah