Android:如何在文件名中获得多个点的文件扩展名?

时间:2013-05-03 06:49:24

标签: file-extension

如何获取名称中包含多个点的文件扩展名?

例如:

image.fromyesterday.hello.jpg

提前致谢!

2 个答案:

答案 0 :(得分:11)

String something = "image.fromyesterday.hello.jpg"; 
String extension = something.substring(something.lastIndexOf("."));

答案 1 :(得分:3)

我认为这会更好:

String suffixOf(String name){
    if(name == null || name.equals("")){
        return "";
    }
    String suffix = "";
    int index = name.lastIndexOf(".");
    if (index != -1 ) {
        suffix = name.substring(index + 1);
    }
    return suffix;
}