import java.io.File;
public class Test {
public static void main(String[] args) {
File file = new File("HelloWorld.java");
String fileName = file.getName();
String fileNameWithoutSuffix = fileName.substring(0,fileName.lastIndexOf("."));//获取没有后缀的文件名
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);//获取文件的后缀名
//beginIndex:索引值加1,意味着从“.”的后一位元素开始;endIndex:没有写结束索引值意味着获取到最后一个元素。
System.out.println("没有后缀的文件名:"+ fileNameWithoutSuffix + " 文件的后缀名:"+ suffix);
}
}