I have the following code for looping through file in a directory and resizing them to 64x64 pixels.
for(File file: friedFiles){
System.out.println(file.getPath());
BufferedImage image = ImageIO.read(file);
Image resize = image.getScaledInstance(64,64, Image.SCALE_DEFAULT);
File resizedFile = new File(path + "\\" + file.getName());
ImageIO.write(convertToBufferedImage(resize), "png", resizedFile);
}
System.out.println("Files finished");
This works fine but after around the 300th image in this directory it breaks, the error it gives is "Caused by: java.io.EOFException: Unexpected end of ZLIB input stream" on the line
BufferedImage image = ImageIO.read(file);
I am unsure what is causing this as the file it is trying to read is a valid image file.
EDIT: Please see the answer I added to this question the issue was a corrupted file header in the original file.
The problem turned out to be a corrupted file header, I was able to fix this problem by regenerating the original file and adding a try catch block to catch an EOFException
so that in any future files it can output an error on that specific file and carry on to parse the rest of directory of files.