Reputation: 19992
I know that we can print to the console in dart using the print() statement.
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.
Thanks
Upvotes: 8
Views: 2036
Reputation: 20865
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);
}
};
}
also if you're developing a console application then checkout the Options class to parse command line arguments
final args = new Options().arguments;
Upvotes: 9