To replace all the path string the file provided the pathstart identifier
private static void changePathInsideFile(String dataPath, String sFILEPATHFOPXCONF,String pathStartIdentifier) { String fileName=sFILEPATHFOPXCONF; boolean changed=false; try { File file = new File(fileName); BufferedReader reader = new BufferedReader(new FileReader(file)); String line = "", oldtext = ""; String c=""; String d=""; String e=""; String baseFolder="Data/"; int index; while((line = reader.readLine()) != null) { index=line.indexOf(baseFolder); while(index>0){// //get substring till the text c=line.substring(0,index); //substring till the pathstartidentifier d=c.substring(0, c.lastIndexOf(pathStartIdentifier)+1); //substring after the index e=line.substring(index, line.length()); line=d+dataPath+e; changed=true; index=line.indexOf(baseFolder, index+1); } oldtext += line + "\r\n"; } reader.close(); //writing the file if(changed){ FileWriter writer = new FileWriter(fileName); writer.write(oldtext);writer.close(); } } catch (IOException ioe) { ioe.printStackTrace(); } }