I'm using the following code to save a BufferedImage to disk:
savePath = new File(path);
savePath.mkdirs();
savePath.createNewFile();
javax.imageio.ImageIO.write(img, "png", savePath);
This particular piece of code is executed off a server, and is run about 10 times for every client request. Most of the time (9 requests out of 10), it works fine, and the image is saved to disk as expected.
However, sometimes I get a java.io.FileNotFoundException (Access is denied) on the ...ImageIO.write() line, and the image is not saved. (The folder is still created)
What can cause the exception?