【问题标题】:How to read console input on M3 Dart如何在 M3 Dart 上读取控制台输入
【发布时间】:2023-04-01 13:32:01
【问题描述】:

在 M3 中,StringInputStream 等类被替换为Stream。如何读取服务器应用程序上的标准输入?

【问题讨论】:

    标签: stream console stdin dart


    【解决方案1】:

    试试这个:

    import 'dart:io';
    import 'dart:async';
    
    void main() {
      print("Please, enter a line \n");
      Stream cmdLine = stdin
          .transform(new StringDecoder())
          .transform(new LineTransformer());
    
      StreamSubscription cmdSubscription = cmdLine.listen(
        (line) => print('Entered line: $line '),
        onDone: () => print(' finished'),
        onError: (e) => /* Error on input. */);
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-08
      • 1970-01-01
      • 1970-01-01
      • 2011-11-08
      相关资源
      最近更新 更多