[ad_1]
I not too long ago began programming cell purposes with flutter. I’ve an issue with studying a file. In apply, whereas the app is working I write a string to a textual content file (and I also can learn it accurately). My want is to learn from this file each time the app is accessed; subsequently, within the initState () operate I name the readContent () operate however I get the next message: “FileSystemException: Can’t open file, path=”/var/cell/Containers/Information/Utility/F8A5A202-45C9-47F6-93C9-E4BAE2AF3C7E/Paperwork/counter.txt” (OS Error: No such file or listing, errno = 2)”. Might you assist me?
That is my code:
Future<String> get _localPath async {
last listing = await getApplicationDocumentsDirectory();
print("listing path: "+listing.path);
return listing.path;
}
Future<io.File> get _localFile async {
last path = await _localPath;
return io.File('$path/counter.txt');
}
String datas = "";
//questa funzione viene richiamata all'avvio della schermata e serve per leggere il valore del flag checkSendingReport dal file
@override
void initState() {
tremendous.initState();
readContent().then((String worth) {
print(worth);
setState(() {
String knowledge = worth;
Record data_file_split = knowledge.break up("#");
checkSendingReport = data_file_split[1];
check_sending_report = data_file_split[1];
});
});
}
//Questa funzione serve per leggere il file locale scritto in precenza
Future<String> readContent() async {
strive {
last file = await _localFile;
// Learn the file
String contents = await file.readAsString();
//Returning the contents of the file
return contents;
} catch (e) {
// If encountering an error, return
return 'Error! '+e.toString();
}
}
//questa funzione serve per scrivere il file locale
Future<io.File> writeContent(datetime) async {
last file = await _localFile;
//Setto a real la variabile flag check_sending_report
check_sending_report = true;
//Creo la stringa da inserire nel file: composta da datetime#flag
String data_file = datetime + "#" + check_sending_report.toString();
// Write the file
return file.writeAsString(data_file);
}
[ad_2]
