Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

javax.imageio.IIOException: Can't create an ImageInputStream!  RSS feed

Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there,

I am getting the exception from the title of this post whenever I try to run the following code:

File imageFile = new File (path);
BufferedImage img =;

I know that it a permissions-related problem not that the image has the read-only flag checked, but, that my user (at an OS level) does not have permission to open the image - I'm not even capable of opening it directly with the OS.

My question to YOU guys is, is there any way to check the permissions before trying to open a File. I do not want to use
File.canRead(), File.canWrite(), or File.canExecute() because they check whether the file has the read-only flag checked, but that does not work for me.
What I need to check is if the user has permissions over the object he's trying to open.

This is the read method from the ImageIO class.

public static BufferedImage read(File input) throws IOException {
1275 if (input == null) {
1276 throw new IllegalArgumentException ("input == null!");
1277 }
1278 if (!input.canRead()) {
1279 throw new IIOException ("Can't read input file!");
1280 }
1282 ImageInputStream stream = createImageInputStream(input);
1283 if (stream == null) {
1284 throw new IIOException ("Can't create an ImageInputStream!");
1285 }
1286 return read(stream);
1287 }

Unfortunately it uses File.canRead() to check permissions and that's not what I need.

Any help is greatly appreciated!
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!