javax.imageio.IIOException: Can't read input file [duplicate]
javax.imageio.IIOException: Can't read input file [duplicate]
This question already has an answer here:
I am building a program that compresses a given image and saves it as a JPEG. This is the error message I get:
Exception in thread "main" javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(Unknown Source)
at JPEGCompression.main(JPEGCompression.java:23)
Here is my main:
public class JPEGCompression {
public static void main(String args) throws IOException
String imageFile = "/tmp/garden.png";
BufferedImage i = ImageIO.read(new File(imageFile)); // this line produces the error
showImage("Original Image", i);
compressAndShow(i, 0.7f);
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
@Quirliom wow it was that simple! That has worked, thank you :)
– pacman4565
Nov 23 '13 at 19:22
Please add an answer to this question or accept the below answer if it was helpful. Right now this is not very helpful to others.
– Gray
Jul 22 '15 at 21:43
2 Answers
2
I have also met this problem. The answer is that the model of the picture is wrong. So you should change the model of the picture from 'CMYK' TO 'RGB'. CMYK is for printer, and RGB is for computer. You can use photoshop or imageMagick to get it done.
You have no checks for if the file exists / have permissions for the file, that would be my first debugging step.
Also try the following: String imageFile = "./tmp/garden.png";
String imageFile = "./tmp/garden.png";
I always put a . before my slash to tell it I'm talking about the current directory, though I don't think it is required.
.
/ and ./ mean completely different things, and ./ can be simply removed, being merely redundant.– user207421
Oct 4 '16 at 3:44
/
./
./
Are you sure you need the leading slash on the image path?
– Sinkingpoint
Nov 23 '13 at 19:19