获取上传的文件,对文件名进行重命名时要用到。取得文件名,根据.
切割,分别获得文件名称和文件类型(后缀名)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| import java.io.File;
public class FileSuffix {
public static String getSuffixWithPoint(String filename) { File file = new File(filename); String fileName = file.getName(); String suffix = fileName.substring(fileName.lastIndexOf(".")); return suffix; }
public static String getSuffixWithoutPoint(String filename) { File file = new File(filename); String fileName = file.getName(); String suffix = fileName.substring(fileName.lastIndexOf(".") + 1); return suffix; } }
|