replaceFileContent static method
Future<void>
replaceFileContent(
{ - required String filePath,
- required String newContent,
- bool createIfNotExists = false,
})
Implementation
static Future<void> replaceFileContent({
required String filePath,
required String newContent,
bool createIfNotExists = false,
}) async {
try {
final file = File(filePath);
if (createIfNotExists == false) {
if (!await file.exists()) {
// await file.create(recursive: true);
throw FormatException('❌ File not found: $filePath');
}
} else {
await file.create(recursive: true);
}
await file.writeAsString(newContent);
} catch (e) {
rethrow;
}
}