All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.afu.utils.files.FileUtils Maven / Gradle / Ivy

package io.afu.utils.files;

public class FileUtils {


    /**
     * 获取带后缀的文件名
     * @param filePath 文件路径
     * @return String
     */
    public static String getFileNameByFilePath(String filePath){
        String fileName = null;
        if (filePath.contains("\\")){
            fileName =filePath.substring(filePath.lastIndexOf("\\")+1,filePath.length());
        }else {
            fileName = filePath.substring(filePath.lastIndexOf("/")+1,filePath.length());
        }
        return fileName;
    }

    /**
     * 获取不带后缀的文件名
     * @param filePath 文件路径
     * @return String
     */
    public static String getFileNameWithoutSuffix(String filePath) {
        String nameWithoutSuffix = null;
        String fileName = getFileNameByFilePath(filePath);
        nameWithoutSuffix = fileName.substring(0,fileName.lastIndexOf("."));
        return nameWithoutSuffix;
    }



    public static String getFileNameByUrl(String url){
        String[] strs = url.split("\\?");
        String pureUrl = strs[0];
        return pureUrl.substring(pureUrl.lastIndexOf("/")+1,pureUrl.length());
    }





}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy