经常会用到的对文件的操作,做一个记录。
public void getSuffix(File file) {
String fileName = file.getName();
/**
* 用文件的名字或者路径都可以。 String filePath=file.getPath(); String
* suffix=filePath.substring(filePath.lastIndexOf("."),
* filePath.length());
*/
String suffix = fileName.substring(fileName.lastIndexOf("."),
fileName.length());
System.out.println("文件的后缀(.xxxx的形式)为:" + suffix);
}