You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
708 B
Dart

import 'dart:io';
class ReadData {
static const prefix = 'lib/data/';
static Future<List<T>> readFile<T>(String classString, {bool test}) async {
var fileName = prefix + classString.toLowerCase() + (test ?? false ? 'test' : '') + '.data';
var file = File(fileName);
var contents = <T>[];
// print('open file "$fileName"');
if (await file.exists()) {
var contentStrings = await File(fileName).readAsLines();
if (T == num) {
contents = contentStrings.map(num.parse).toList() as List<T>;
} else if (T == String) {
contents = contentStrings as List<T>;
}
} else {
print('File "$fileName" not found.');
}
return contents;
}
}