I have a String which contains path to the some file, for ex. "/sdcard0/Lewis/cache.obb".
How I can get file extension (w/out dot) from that String?
Note: file extension can be different, for ex. ".tar.gz".
I have a String which contains path to the some file, for ex. "/sdcard0/Lewis/cache.obb".
How I can get file extension (w/out dot) from that String?
Note: file extension can be different, for ex. ".tar.gz".
If you have the file path/URL, you can use MimeTypeMap#getMimeTypeFromExtension() like this:
public static String getFileType(String url)
{
    String type = null;
    String extension = MimeTypeMap.getFileExtensionFromUrl(url);
    if (extension != null) {
        MimeTypeMap mime = MimeTypeMap.getSingleton();
        type = mime.getMimeTypeFromExtension(extension);
    }
    return type;
}
And then you just call it like this:
String fileType = YourClass.getFileType(file);
 
    
    Try this if (fileName != null) { File imageFile = new File(fileName);
String fileType=fileName.substring(imageFile.getName().length(),fileName.length());
}
