【发布时间】:2021-07-03 19:45:14
【问题描述】:
我正在尝试在我的应用程序中将 txt 文件导出为 srt(以纯文本形式编写),并且在我看到指定文件夹中名称正确的 srt 但这些文件为 0B 和我不确定哪里没有完全发挥作用?
void add() async {
fileName = _fileNameCon.text.toString();
print("filename ---------> " + fileName);
newSubFile(fileName);
setState(() {
_fileNameCon.clear();
srt = "";
subnumber = 1;
stopWatch.reset();
});
}
void newSubFile(String title) async {
try {
// this is an android specific directory
Directory directory = await getExternalStorageDirectory();
final path = directory.path;
File newSrt = await File('$path/' + title + ".srt").create();
var writer = newSrt.openWrite();
print("----attempting to write to $path/$title----");
writer.write(srt);
writer.close();
print("----closing----");
} catch (e) {
print(e);
}
}
【问题讨论】:
-
你应该调用 writer.flush();在 writer.close(); 之前
标签: flutter