Android:将文件保存到内部数据时需要 BufferedOutputStream 吗?
我想将字符串保存到文件中并将其读回,因此我遵循了这两个示例:
但是,两者都没有使用 BufferedOutputStream 包装器,而 FileOutputStream 的文档推荐它。
这样做是为了有一个更简单的例子还是在 Android 上真的没有必要?答案是否也适用于 InputStream?
问候, 海蜇
I wanted to save a string to a file and read it back, so I followed those two examples:
However, in both of them, no BufferedOutputStream wrapper is used, while the docu of FileOutputStream recommends it.
Was this done to have an easier example or is it really not necessary on Android? And does whatever the answer is also apply to the InputStream?
Regards,
jellyfish
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,示例的作者提前知道输出数据的大小很小。如果您有“大量”数据要写入(您通常无法提前确定绝对确定性),那么您实际上只需要缓冲版本。
JavaDocs for BufferedOutputStream 很好地强调了这一点......
In this case, the authors of the examples know the size of the output data to be small ahead of time. You really only need the Buffered version if you have "large" amounts of data to write (which you usually don't know for absolute certainty ahead of time).
The JavaDocs for BufferedOutputStream highlights this well...