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.






Are you sure you need the leading slash on the image path?

– Sinkingpoint
Nov 23 '13 at 19:19






@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


/


./


./

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ