I’m trying to read a TIFF image from file using BufferedImage. The following is my code:
String filename = "/image/parrot.tiff";
File f = new File (filename);
try{
BufferedImage img = ImageIO.read(f);
}catch (Exception e){
System.out.println("Something went wrong!");
}
But it isn’t working. I have a method called testInput just to test if the file was read properly:
public void testInput(){
System.out.println(f.exists());
System.out.println(f.canRead());
System.out.println(f.canWrite());
}*/
The three of them would always return “false” and the above code always returns “Something went wrong!”. I already added JAI ImageIO for the plug-in to read TIFF image. Any idea what seems to be the problem?
It may seem silly, but are you sure your file is placed in
?
According to the Javadoc, exists() returns :
So I think the path may be wrong. According to your comment, I think the correct path should be
If it isn’t, try
In all cases, you must understand better how file path are managed in Java (and in most other languages) 😉