File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes javax.imageio.IIOException: Can't create an ImageInputStream! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "javax.imageio.IIOException: Can Watch "javax.imageio.IIOException: Can New topic
Author

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

Eric Lopez-Fernandez
Greenhorn

Joined: Oct 13, 2011
Posts: 17
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javax.imageio.IIOException: Can't create an ImageInputStream!