0

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

例如:

image.fromyesterday.hello.jpg

提前致谢!

4

2 回答 2

11
String something = "image.fromyesterday.hello.jpg"; 
String extension = something.substring(something.lastIndexOf("."));
于 2013-05-03T06:53:00.690 回答
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;
}
于 2014-08-24T13:45:13.197 回答