`javax.imageio.ImageIO`是否需要文件锁定? [英] Does `javax.imageio.ImageIO` require file locking?
问题描述
我的应用将图像保存到文件夹中。同时另一个软件监视此文件夹并打印粘贴的图像。
My app is saving images into a folder. Simultaneously another piece of software watches over this folder and prints pasted images.
我遇到的问题是打印应用程序可以在打印机上发送一半渲染图像或者没有反应保存图像。
Problem I've encountered is that printing app can send on printer half rendered image or doesn't react to saved images at all.
我正在使用 javax.imageio.ImageIO.write(RenderedImage im,String formatName,File output)
to将 BufferedImage
保存到 png
格式。
I'm using javax.imageio.ImageIO.write(RenderedImage im, String formatName, File output)
to save BufferedImage
into png
format.
如果需要锁定请提供带显式锁的代码示例。如果不解释原因。
If locking required please provide a code example with explicit locks. If not explain why.
我已经在 Windows
, JRE 1.8上进行了测试
推荐答案
基本上,您应该将图像写入临时文件,然后将其重命名为最终文件名。这样,文件就会在其他应用程序意识到之前完全写入。
Basically, you should write the image to a temporary file and then rename it to the final file name. this way the file is completely written before the other app becomes aware of it.
这篇关于`javax.imageio.ImageIO`是否需要文件锁定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!