java获取文件的后缀名称

import java.io.File;

public class GetFileName {

/** 
 *author: yinxian
 */  
public static void main(String[] args) {  
    System.out.println(getFileNameExtension(fileString)); 
}  

/**
 * 获取后缀名称
 * @param filePath
 * @return
 */
String getFileNameExtension(String filePath){
    File file = new File(filePath);
    String fileName = file.getName();
    String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
    return suffix;
}

}

猜你喜欢

转载自blog.csdn.net/Yin_Xian/article/details/78455618