供参考,谢谢1- public class Test8 {
- public static void main(String[] args) {
- String str = getExtension("hello.txt");
- System.out.println(str);
- }
- public static String getExtension(String fileName) {
- int index = fileName.lastIndexOf('.');
- System.out.println(index);
- String extension = fileName.substring(index+1);
- return extension;
- }
- }
复制代码 |