This is a question that has been asked like 100 times on this site, but I have looked at all of them and even though they all were solved, none of the solutions worked for m
I was facing this error due to a bug in my code. I was trying to extract (conn.getInputStream()) from a different connection object than what it should have been. I fixed the connection object variable and it started working.
BufferedImage image;
try (InputStream in = new BufferedInputStream(conn.getInputStream())) {
image = ImageIO.read(in);
File file = new File(fullImageFilePath);
synchronized (file.getCanonicalPath().intern()) {
if (!file.exists()) {
ImageIO.write(image, "png", file);
}
}
}