FilenameUtils { public static String getExtension(String path) { if (path == null || path.isEmpty()) { return null; } int dotPos = path.lastIndexOf("."); int dirPos = path.lastIndexOf("/"); if (dirPos > dotPos || dotPos == -1) { return null; } else { return path.substring(dotPos + 1); } }  static String getPath(Context context, Uri uri); static String getExtension(String path);  }
@Test public void getExtension() throws Exception { assertNull(FilenameUtils.getExtension(null)); assertNull(FilenameUtils.getExtension("")); assertNull(FilenameUtils.getExtension("/b/c")); assertNull(FilenameUtils.getExtension("/b.rtl/c")); assertEquals("gif", FilenameUtils.getExtension("/b.rtl/c.gif")); }