writeFile static method

bool writeFile(
  1. String path,
  2. String content, {
  3. bool append = false,
})

Implementation

static bool writeFile(String path, String content, {bool append = false}) {
  try {
    final file = File(path);
    if (append && file.existsSync()) {
      file.writeAsStringSync(content, mode: FileMode.append);
    } else if (append) {
      file.createSync(recursive: true);
      file.writeAsStringSync(content, mode: FileMode.append);
    } else {
      file.createSync(recursive: true);
      file.writeAsStringSync(content);
    }
    return true;
  } catch (e) {
    stderr.writeln('writeFile error: $e');
    return false;
  }
}