dartdart-io

Doesn't work stdout.write Method but can work stdout.writeln


import 'dart:io'
void main(){
stdout.write("abc");}

that code doesn't worked but

void main(){
stdout.writeln("abc");}

was work!! output is "abc" and

void main(){
stdout.write("abc");
stdout.writeln("def");}

out put is "abcdef" I can't understand this happend...


Solution

  • Both write and writeln are non-blocking, with the difference that writeln is causing the buffer to be flushed. Your first code would work if you await a flush before ending your program:

    import 'dart:io'
    
    void main() async {
        stdout.write("abc");
        await stdout.flush();
    }