3 changed files with 136 additions and 19 deletions
			
			
		@ -0,0 +1,47 @@
				@@ -0,0 +1,47 @@
					 | 
				
			||||
package com.ruoyi.common.utils.file; | 
				
			||||
 | 
				
			||||
import java.io.File; | 
				
			||||
import org.apache.commons.lang3.StringUtils; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * 文件类型工具类 | 
				
			||||
 * | 
				
			||||
 * @author ruoyi | 
				
			||||
 */ | 
				
			||||
public class FileTypeUtils | 
				
			||||
{ | 
				
			||||
    /** | 
				
			||||
     * 获取文件类型 | 
				
			||||
     * <p> | 
				
			||||
     * 例如: ruoyi.txt, 返回: txt | 
				
			||||
     *  | 
				
			||||
     * @param file 文件名 | 
				
			||||
     * @return 后缀(不含".") | 
				
			||||
     */ | 
				
			||||
    public static String getFileType(File file) | 
				
			||||
    { | 
				
			||||
        if (null == file) | 
				
			||||
        { | 
				
			||||
            return StringUtils.EMPTY; | 
				
			||||
        } | 
				
			||||
        return getFileType(file.getName()); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 获取文件类型 | 
				
			||||
     * <p> | 
				
			||||
     * 例如: ruoyi.txt, 返回: txt | 
				
			||||
     * | 
				
			||||
     * @param fileName 文件名 | 
				
			||||
     * @return 后缀(不含".") | 
				
			||||
     */ | 
				
			||||
    public static String getFileType(String fileName) | 
				
			||||
    { | 
				
			||||
        int separatorIndex = fileName.lastIndexOf("."); | 
				
			||||
        if (separatorIndex < 0) | 
				
			||||
        { | 
				
			||||
            return ""; | 
				
			||||
        } | 
				
			||||
        return fileName.substring(separatorIndex + 1).toLowerCase(); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
					Loading…
					
					
				
		Reference in new issue