判断文件名后缀名,可以用String 类的方法endsWith("后缀")
例如:
String str="星辰变.txt";
String str2="寸芒.mobl";
if( !str.endsWith(".txt") ){ //判断后缀不是.txt, 输出的格式是txt
System.out.println("输出的格式是txt");
}
if(str2.endsWith(".mobl")){ //判断后缀是.mobl, 输出的格式是mobl
System.out.println("输出的格式是mobl");
}
控制台输出的结果:
输出的格式是mobl