是否可以从Dart中的控制台读取? [英] Is it possible to read from console in Dart?

查看:694
本文介绍了是否可以从Dart中的控制台读取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我们可以使用print()语句在dart中打印到控制台。

I know that we can print to the console in dart using the print() statement.

我想知道是否可以从控制台读取数据。我做了一个搜索,并查看了dart:io包,但找不到任何参考。

I want to know if it is possible to read data from console. I did a search and also looked in the dart:io package, but couldn't find any reference.

感谢

推荐答案

您可以使用 StringInputStream 阅读from stdin like this

You can use StringInputStream to read from stdin like this

#import("dart:io");

main() { 
  var stream = new StringInputStream(stdin); 
  stream.onLine = () { 
    var line = stream.readLine(); 
    if (line != null) { 
      print(line); 
    } 
  }; 
} 

如果你正在开发一个控制台应用程序,然后检出 Options 类来解析命令行参数

also if you're developing a console application then checkout the Options class to parse command line arguments

final args = new Options().arguments;

这篇关于是否可以从Dart中的控制台读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆