java:
java.io.File a=new java.io.File(str1);
try{
BufferedInputStream bin = new BufferedInputStream(new FileInputStream(a));
byte[] buff = new byte[(int)a.length()];
bin.read(buff);
FileOutputStream fout = new FileOutputStream(a);
String str = new String(buff);
String[] lines = str.split("\n");
String line_changed="";
for(String line : lines){
line_changed = line.replaceAll("8005",port1);
line_changed = line_changed.replaceAll("8080",port);
line_changed = line_changed.replaceAll("8009",port2);
fout.write((line_changed+"\n").getBytes());
}
fout.flush();
fout.close();
bin.close();
}catch(FileNotFoundException ex){
ex.printStackTrace();
}catch(IOException ioe){
ioe.printStackTrace();
}
groovy:
private def readtomcatpath={
new java.io.File("/opt/tomcatpath.config").eachLine{line->
tomcatpath="${line}".substring(11)
}
}