ImageIO.write 是否被缓冲?
我应该写
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file));
ImageIO.write(im, "JPEG", os);
而
ImageIO.write(im, "JPEG", file);
不是默认情况下是否缓冲 ImageIO 文件操作?
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您传入
File
,底层实现将直接写入RandomAccessFile
(在"rw"
模式下创建),因此没有缓冲。具体来说,FileImageOutputStream
将用作ImageOutputStream
。If you pass in a
File
, the underlying implementation will write directly to aRandomAccessFile
(created in"rw"
mode), so no buffering. Specifically, aFileImageOutputStream
will be used as theImageOutputStream
.我相信这取决于 IIORegistry 的具体实现,我认为它与系统相关。
我希望它能被缓冲,但我想你可以选择第一个选项来完全确定。
I believe it depends on the specific implementation of the
IIORegistry
which I suppose is system dependent.I would expect it to be buffered, but I suppose you could go with the first option to be completely sure.
您将需要使用 BufferedOutputStream (如问题中提到的例 1)。
默认情况下,ImageIo.write 不被缓冲。这取决于您在参数中传递给它的内容。如果传递 File 对象,则不会缓冲写入。
You will need to use BufferedOutputStream (As in ex. 1 mentioned in question).
ImageIo.write is not buffered by default. It depends upon what you pass to it in arguments. In case of File object being passed it won't be buffered write.