package com.skr.mdm.util;

import org.springframework.boot.system.ApplicationHome;

import java.io.File;

/**
 * @author nfq
 * @date 2020/8/12 14:55
 */
public class FilePathUtil {

    /**
     * 获取文件所在jar包绝对路径
     * @param sourceClass
     * @return
     */
    public static String getFileAbsolutePath(Class<?> sourceClass) {
        ApplicationHome applicationHome = new ApplicationHome(sourceClass);
        File jarPath = applicationHome.getSource();
        String absolutePath = jarPath.getParentFile().toString();
        return absolutePath;
    }

    /**
     * 获取项目绝对路径
     *
     * @param sourceClass
     * @return
     */
    public static String getProjectAbsolutePath(Class<?> sourceClass) {
        ApplicationHome applicationHome = new ApplicationHome(sourceClass);
        File jarPath = applicationHome.getSource();
        String absolutePath = jarPath.getParentFile().getParentFile().toString();
        return absolutePath;
    }
}
