Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Eric Lopez-Fernandez
Greenhorn
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 = ImageIO.read(imageFile);

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 }
1281
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic