I have requirement to get from user input file which should be image only of specified type. E.g. only JPEG
s. Other files must be rejected.
So I implemented naive basic check for file
fileName.toLowerCase().endsWith(".jpg") || fileName.toLowerCase().endsWith(".jpeg")
So if user uploaded file.png, this file was rejected. But then users realized, that if they simply rename file.png to file.jpg, the file will be uploaded.
Is there way to detect if supplied file is valid image of given type using only JAVA SDK
without external jars? (note I'm still working with JDK6). Thanks.