Skip to content

Instantly share code, notes, and snippets.

@LorisBachert
Created November 26, 2015 10:34
Show Gist options
  • 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