flutter - Is there any way to write to a pre-existing text file in flutter?
问题描述
I have a txt file that I need to write to. I know that I can't write to this using File IO, so is there any way to write to this file?
解决方案
If you want to open the file in append mode you have to pass the file mode in your writeAsString()
function else it will over write the file.
import 'dart:async';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:path_provider/path_provider.dart';
Future<File> writeCounter(int counter) async {
final file = await File('your_path.txt');
// Write the file
return file.writeAsString('$counter',mode: FileMode.append);
}
}
推荐阅读
- javascript - 获取未定义为函数输出
- python - 如何在pywinauto中通过正则表达式标题搜索孩子/后代?
- react-native - 反应本机 mapDispatchToProps 不起作用
- python - 停止 Jupyter 自动缩进新行大量的非整数制表符?
- quantum-computing - 使用哈密顿量实现 CNOT 门
- swift - Kentico-cloud Swift SDK ContentType 没有可用的属性
- c# - 如何将所有 AD 用户添加到 ComboBox
- paypal - 在哪里查看“沙盒”支付列表?
- optimization - 关于神经网络的基于梯度下降的优化
- php - 如何显示课程总数?