> i want to check if a file is .gif file and if so, do
> some action. how to do this using file io package
Easy:
if (thefile.getName().toLowerCase().endsWith(".gif")) ...
Complicated:
look up the GIF specs for the file header definitions and look whether those in your file match.
I dimly recall seeing something in javax.imageio that has heuristics to check file type based on the first few bytes of a file. (Basically the logic already described.) So maybe this logic is already available in the API.
On the other hand my memory could be entirely wrong. Check the docs to find out one way or the other.
> I dimly recall seeing something in javax.imageio that
> has heuristics to check file type based on the first
> few bytes of a file. (Basically the logic already
> described.) So maybe this logic is already available
> in the API.
The easiest way would be to simply load the image, if the OP needs to use the images instead of just to handle te file. I'm just not sure whether ImageIO supports GIF. It didn't use to, IIRC.