Does `javax.imageio.ImageIO` require file locking?

眉间皱痕 提交于 2019-12-12 01:47:28

问题


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.

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.

I've tested on Windows, JRE 1.8


回答1:


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.




回答2:


You probably want to implement some kind of locking mechanism that files are only read when they are completely written, or not at all.



来源:https://stackoverflow.com/questions/29870938/does-javax-imageio-imageio-require-file-locking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!