readFile static method
Implementation
static String readFile(String filePath,
{Encoding encoding = utf8, saveMode = false}) {
String? text = null;
try {
text = File(filePath).readAsStringSync(encoding: encoding);
if (saveMode && text.isEmpty) {
// if it is empty, set to null and try other ways
text = null;
}
} on Exception catch (e, s) {
text = null;
}
if (text == null) {
for (var tryEncoding in fallBackEncodings) {
try {
text = File(filePath).readAsStringSync(encoding: tryEncoding);
if (text.isNotEmpty) {
break;
}
} on Exception catch (e, s) {
// ignore
}
}
}
return text!;
}