获取临时存储路径
void _requestTempDirectory() async {
Directory tempDir = await getTemporaryDirectory();
setState(() {
tempPath = tempDir.path;
});
}
往文件写数据
_add() async {
File file = new File('$tempPath/user.txt');
await file.writeAsString('用户名:$username\n密码:$pwd');
setState(() {
_result = '写入成功,请查询';
});
}
读取文件数据
_query() async {
try {
File file = new File('$tempPath/user.txt');
_result = '查询成功\n' + await file.readAsString();
} on Exception catch (e) {
_result = ' exception: $e';
}
setState(() {});
}
删除
_delete() {
File file = new File('$tempPath/user.txt');
file.deleteSync(recursive: false);
setState(() {
_result = '删除成功,请查看';
});
}
网友评论