public static boolean replaceFileStr(String filepath, String sourceStr, String targetStr)
{
try
{
FileReader fis = new FileReader(filepath);
char[] data = new char[1024];
int rn = 0;
StringBuilder sb = new StringBuilder();
while ((rn = fis.read(data)) > 0)
{
String str = String.valueOf(data, 0, rn);
sb.append(str);
}
fis.close();
String str = sb.toString().replace(sourceStr, targetStr);
FileWriter fout = new FileWriter(filepath);
fout.write(str.toCharArray());
fout.close();
return true;
}
catch (FileNotFoundException e)
{
e.printStackTrace();
return false;
}
catch (IOException e)
{
e.printStackTrace();
return false;
}
}