问题描述
- StringWriter 调用flush后为什么缓存区还有内容??
-
如题:StringWriter sw=new StringWriter(); sw.write("aa"); System.out.println("1:"+sw); sw.flush(); System.out.println("2:"+sw);
两处都有结果,flush后缓存没有清空吗?
解决方案
找到了,
public void flush() {
}
Flush is suppose to ensure that all characters written to the Writer are
fully processed. For example, if the Writer were outputting to a
terminal, calling flush would ensure that all characters appeared on the
screen. Since StringWriter doesn't do any buffering (that is, it
updates its internal buffer on every write), flushing it is a no-op.
解决方案二:
这竟然是个空方法……………………
时间: 2024-11-02 02:57:55