请告诉我此刻的情况。我不太明白flush()
使用输出流时该方法究竟如何工作。从我读到的内容来看,我明白独立缓冲区刷新和数据写入需要它。有专门BufferedOutputStream
用于BufferedWriter
字节和字符的缓冲流,其中有一个内部缓冲区,以免每次都访问外部源(文件、网络套接字等)。那么,在即时写入数据的常规“非缓冲”类中,这种方法有什么意义呢?
import java.io.*;
public class Program {
public static void main(String[] args) {
try(FileWriter writer = new FileWriter("note.txt")
{
String text = "Some text";
writer.write(text);
writer.flush();
}
catch(IOException ex){
System.out.println(ex.getMessage());
}
}
}