I'm confused with the console output in these little pieces of code:
public static void main(String[] args) throws Exception {
String path = "/hi/my/path";
System.out.println(path);
System.err.println("ERROR!!!");
}
I would expect output in a linear way:
/hi/my/path
ERROR!!!
But I'm getting:
I also tried with flush()
as in the possible duplicate:
public static void main(String[] args) throws Exception {
String path = "/hi/my/path";
System.out.println(path);
System.out.flush();
System.err.println("ERROR!!!");
System.err.flush();
}
But that gets:
And if I run:
public static void main(String[] args) throws Exception {
String path = "/hi/my/path";
System.out.println(path);
System.err.println(path);
System.out.println("ERROR!!!");
System.err.println("ERROR!!!");
}
I get:
And even stranger, if I execute this:
public static void main(String[] args) throws Exception {
String path = "/hi/my/path";
System.out.println(path);
System.out.flush();
System.err.println(path);
System.err.flush();
System.out.println("ERROR");
System.out.flush();
System.err.println("ERROR!!!");
System.err.flush();
}
I get:
Is there something I'm missing? When I debug it, everything goes in a linear way and the output is the expected output, but not when I run the program normally.
Is there a higher priority for the err
output stream relative to out
? Is System.err
faster than System.out
for something?
Looking at the System
source code, err
and out
are both PrintStream
.
Any idea why is this happening?