Created
November 26, 2015 10:34
-
-
Save LorisBachert/40b8ea01839841363691 to your computer and use it in GitHub Desktop.
Detecting the type of a file by its name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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