问题描述
限时送ChatGPT账号..我有一个文本文件(里面有内容),我想向它附加文本.这是我的代码:
I've got a text file (it has content in it) and I want to append text to it. This is my code:
File outputFile=new File('hello.out');
outputFile.createSync();
List<String> readLines=files[i].readAsLinesSync(Encoding.UTF_8);
for(int j=0;j<readLines.length;j++)
{
outputFile.writeAsStringSync(readLines[j], FileMode.APPEND); }
出于某种原因,Dart 在FileMode.APPEND"下放了一条黄线,表示这是一个额外的参数".但是,此链接 http://api.dartlang/docs/releases/latest/dart_io/File.html 声称它是可选的.
For some reason Dart put a yellow line under "FileMode.APPEND" and it says that it's an "extra argument". However, this link http://api.dartlang/docs/releases/latest/dart_io/File.html claims that it is optional.
推荐答案
FileMode 是一个可选的命名参数,因此您在调用它时必须指定其名称 ('mode').要解决您的问题,请更改此设置:
The FileMode is an optional, named parameter, so you have to specify its name ('mode') when you call it. To solve your problem, change this:
outputFile.writeAsStringSync(readLines[j], FileMode.append);
为此:
outputFile.writeAsStringSync(readLines[j], mode: FileMode.append);
这篇关于如何将字符串连接到现有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论