FileOutputStream flush()
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了FileOutputStream flush()相关的知识,希望对你有一定的参考价值。
FileOutputStream 继承 OutputStream ,flush方法查看源码方法体为空,所以flush没起到清除缓存的作用
改用BufferedOutputStream再调用flush()能成功清除缓存
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSSS"); Date curDate = new Date(System.currentTimeMillis()); File file = new File(fileDir + sdf.format(curDate) + ".xml"); if (!file.exists()) { file.createNewFile(); } bos = new BufferedOutputStream(new FileOutputStream(file)); if (soap.length() <= 1024) { bos.write(soap.getBytes()); bos.flush(); } else { int beginIndex = 0; int endIndex = 1024; while (beginIndex < soap.length()) { bos.write(soap.substring(beginIndex, (endIndex <= (soap.length())) ? endIndex : (soap.length())).getBytes()); bos.flush(); beginIndex = endIndex; endIndex = beginIndex + 1024; } } bos.close();
以上是关于FileOutputStream flush()的主要内容,如果未能解决你的问题,请参考以下文章
HBase的几种调优(GC策略,flush,compact,split)