I have the following code:
String nameAndPath = "C:\\example\\folder\\filename.png";
BufferedImage image = addInfoToScreenshot(); //this method works fine and returns a BufferedImage
ImageIO.write(image, "png", new File(nameAndPath));
现在,路径
C:\example\folder\
不存在,因此我会收到一个异常抛出消息:(系统找不到指定的路径)
我该如何让ImageIO自动创建路径,或者有什么方法可以自动创建路径?在此代码的早期版本中,我使用FileUtils.copyFile保存图像(以File对象的形式),这将自动创建路径。我该如何复制这个过程?我可以再次使用FileUtils.copyFile,但我不知道如何将BufferedImage对象“转换”为File对象。