【问题标题】:Writing endlines to files in with dart:io使用 dart:io 将结束行写入文件
【发布时间】:2018-12-10 09:31:12
【问题描述】:

我在 Windows 上使用 WebStorm,并且我有简单的命令行 dart 应用程序:

import 'dart:io';

main(List<String> arguments) {
  File testFile = new File("test.txt");
  testFile.writeAsStringSync("AAA\nBBBBB\rCCCCC");
}

程序成功执行,但是通过记事本打开的 .txt 文件似乎包含

AAABBBBBCCCCC

但是,如果我尝试将内容传递到其他环境(WebStorm、StackOverflow 问题文本区域),则文本显示为

AAA
BBBBB
CCCCC

我觉得我缺少一些基本的东西......有什么想法吗?

【问题讨论】:

  • 正如 Günter Zöchbauer 所说:Windows 记事本仅识别默认的 CRLF 行尾,而浏览器/WebStorm 将使用任何已知行尾。最新的 Windows 10 版本(Spring Creators Update 或任何名称)中的 AFAIK 记事本终于了解了其他行尾。同时尝试记事本++...

标签: windows dart webstorm notepad dart-io


【解决方案1】:

Windows 默认使用\r\n 作为行尾。

并非所有应用程序都将 \r\n 视为 Windows 上的行尾。
这种行为与 Dart 没有任何关系,这只是一些应用程序解释这些代码的方式。

【讨论】:

  • 它接缝你是正确的......对于我的用例,生成的文件运行良好,只有记事本没有显示 endlines
猜你喜欢
  • 2016-07-10
  • 1970-01-01
  • 1970-01-01
  • 2021-10-02
  • 2013-02-04
  • 2012-12-29
  • 2013-07-04
  • 1970-01-01
  • 2013-09-26
相关资源
最近更新 更多