一个PrintStream 可以被创建为自动刷新的;这意味着当一个字节数组(bytearray)被写入,或者某个println 方法被调用,或者一个换行字符或字节(‘/n’)被写入之后,PrintStream 类型的flush 方法就会被自动地调用。
System.out和System.err就是PrintStream类,所以你需要注意哦。
package com.yinbodotcc;
public class PrivateClass
{
public static void main(String[] args) throws Exception
{
String greeting = "Hello World";
byte[]b=greeting.getBytes();
//第一种
System.out.write(b);
//第二种要flush
for(int i = 0; i < greeting.length(); i++)
System.out.write(greeting.charAt(i));
System.out.flush();//或者System.out.println()或者System.out.write('/n');
}
}