use a regex or lastIndexOf(".") with substring() rather then hardcoding some of possible extensions.