/**
String fileName1 = "logo.png";//要png
String fileName2 = "jquery.1.1.2.js";//要js
String ext = getExtByName(fileName1);
System.out.println(ext);//png
ext = getExtByName(fileName2);
System.out.println(ext);//js
}文件名
望采纳!!!
通过lastIndexOf获取指定字符串最后一次出现的位置,来截取文件名称:
public class Main {
public static void main(String argu[]) {
System.out.print(getExtByName("1234.aa.png.js"));
}
public static String getExtByName(String name) {
return name.substring(name.lastIndexOf(".") + 1 ,name.length());
}
}
不知道你这个问题是否已经解决, 如果还没有解决的话: