我应该写吗
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file));
ImageIO.write(im, "JPEG", os);
代替
ImageIO.write(im, "JPEG", file);
即 ImageIO 文件操作是否默认缓冲?
谢谢!
我应该写吗
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file));
ImageIO.write(im, "JPEG", os);
代替
ImageIO.write(im, "JPEG", file);
即 ImageIO 文件操作是否默认缓冲?
谢谢!
如果传入 a File
,底层实现将直接写入 a RandomAccessFile
(在"rw"
模式下创建),因此没有缓冲。具体来说, aFileImageOutputStream
将用作ImageOutputStream
.
您将需要使用 BufferedOutputStream (如问题中提到的示例 1)。
ImageIo.write 默认情况下不缓冲。这取决于您在参数中传递给它的内容。如果传递 File 对象,则不会缓冲写入。
我相信这取决于我认为取决于IIORegistry
系统的具体实现。
我希望它会被缓冲,但我想你可以选择第一个选项来完全确定。