我对Java很新颖。Java'System.err.format''''n'后跟'System.out.println',println打印在中间
我使用的是Ubuntu 16.04,JDK 8u101,Netbeans8.1。
当试图验证码:
public static void main(String[] args) {
System.err.format("1st Line %nPrints At 3rd Line,Shouldn't this be In 2nd Line ");
System.out.println("Shouldn't this be the third line,prints at 2nd line");
}
输出是:
This Prints At 1st Line
Shouldn't this be the third line, but prints at 2nd line
This Prints At 3rd Line, Shouldn't this be In 2nd Line
为什么 “System.out.println
” 打印在中间? 不应该最后打印。
我 “%n
” 试图在最后& System.err.flush()
这样的:
System.err.format("1st Line %nPrints At 3rd Line,Shouldn't this be In 2nd Line%n");
System.err.flush();
System.out.println("Shouldn't this be the third line,prints at 2nd line");
还是相同的输出。
您正在打印到两个不同的流,它们只在行的末尾刷新,但System.err在第二行末尾没有刷新。 –