Skip to content

Instantly share code, notes, and snippets.

@geolimber
Last active February 5, 2018 16:46
Show Gist options
  • Save geolimber/a167c936035e09a6041a8c2a5ebac9b7 to your computer and use it in GitHub Desktop.
Save geolimber/a167c936035e09a6041a8c2a5ebac9b7 to your computer and use it in GitHub Desktop.
Simple java class to get file extension
/**
* Simple java class to get file extension.
* Returns null if file starts with point, like .htaccess, and if the file don't have any extension.
* Created by Sergio Marchenko on 05-05-2017.
*/
public class ExtensionChecker {
public static String getFileExtension(String fileName) {
if (!fileName.startsWith(".") && fileName.contains(".")) {
return fileName.substring(fileName.lastIndexOf(".") + 1);
}
else return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment