How to read a file....JPG or BMP

Question:  How would I read a file and than determine if it is a JPG or
BMP???

Any answers would be greatly appreciated...

Thanks in Advance
Bruce