Skip to content

Instantly share code, notes, and snippets.

@LorisBachert
Created November 26, 2015 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LorisBachert/40b8ea01839841363691 to your computer and use it in GitHub Desktop.
Save LorisBachert/40b8ea01839841363691 to your computer and use it in GitHub Desktop.
Detecting the type of a file by its name
public static String getFileExtension(File file) {
return FileHelper.getFileExtension(file.getName());
}
public static String getFileExtension(String name) {
if (! name.contains(".")) {
return "";
}
String[] split = name.split("\\.");
String extension = split[split.length - 1];
return extension;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment