replaceInFile static method

void replaceInFile(
  1. String path,
  2. String from,
  3. String to
)

Replaces all occurrences of from with to in the file at path.

Implementation

static void replaceInFile(String path, String from, String to) {
  final file = File(path);
  if (!file.existsSync()) return;
  final content = file.readAsStringSync();
  file.writeAsStringSync(content.replaceAll(from, to));
}