public class Test {
public static void main(String[] args) {
String str ="abc.jpg";
System.out.println(getSuffix1(str));
System.out.println(getSuffix2(str));
}
//方法1
public static String getSuffix1(String path){
String suffix = "";
suffix = path.substring(path.indexOf(".")+1, path.length());
return suffix;
}
//方法2
public static String getSuffix2(String path){
String suffix = "";
String[] strArray= path.split("\\.");
suffix = strArray[strArray.length-1];
return suffix;
}
} |