package com.cpp.web.utils;


import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ResourceUtils;

import java.io.*;
import java.net.URLDecoder;

/**
 * 操作文件工具类
 *
 * @author tl
 * @date 2022-05-11 10:08:21
 */
@Slf4j
public class CppFileUtil {
    /**
     * 获取项目根路径
     *
     * @return
     */
    public static String getResourceBasePath() {
        // 获取跟目录
        File path = null;
        try {
            path = new File(ResourceUtils.getURL("classpath:").getPath());

        } catch (FileNotFoundException e) {
            // nothing to do
        }
        if (path == null || !path.exists()) {
            path = new File("");
        }

        String pathStr = path.getAbsolutePath();
        try {
            pathStr = URLDecoder.decode(pathStr, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        // 如果是在eclipse中运行，则和target同级目录,如果是jar部署到服务器，则默认和jar包同级
//    pathStr = pathStr.replace("\\target\\classes", "");

        return pathStr;
    }

    public static String getTempCreateFilePath() {
        String path = "/home/syjy/cpp/tempCreateFile";
        return path;
    }


}
