如何将字符串连接到现有文件?

编程入门 行业动态 更新时间:2024-10-19 17:39:58
本文介绍了如何将字符串连接到现有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-17 20:24:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/921542.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   连接到   如何将   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!