code to get extension of a file java code example
Example: java how to read file extension
private static String getFileExtension(File file) {
String extension = "";
try {
if (file != null && file.exists()) {
String name = file.getName();
extension = name.substring(name.lastIndexOf("."));
}
} catch (Exception e) {
extension = "";
}
return extension;
}