截取倒数第三个"/"之后的字符串
public static String getThirdLocation(String url){
//index为最后的“/”字符所在的位置
int index=url.lastIndexOf(File.separator);
//从最后的“/”字符的前一个位置向前找“/”的位置为此index
index=url.lastIndexOf(File.separator,index-1);
//从倒数第二的“/”字符的前一个位置向前找“/”的位置为此index
index=url.lastIndexOf(File.separator,index-1);
//得到倒数第三个“/”之后的字符串
String location=url.substring(index+1);
return location;
}
运行结果: