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);
final exists = await file.exists();
if (!exists) {
if (createIfNotExists) {
await file.create(recursive: true);
} else {
throw Exception('❌ File not found: $filePath');
}
}
await file.writeAsString(newContent);
} catch (e) {
rethrow;
}
}