qa-prevention-gwj/src/main/java/com/zcloud/util/PathUtil.java

40 lines
1.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.zcloud.util;
import java.io.File;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
/**
* 说明:路径工具类
* 作者luoxiaobao
* 官网www.qdkjchina.com
*/
public class PathUtil {
/**获取Projectpath
* @return
*/
public static String getProjectpath(){
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String path = request.getServletContext().getRealPath("/").replaceAll("%20", " ").replaceAll("file:/", "").trim();
return path;
}
/**获取Classpath
* @return
*/
public static String getClasspath(){
String path = (String.valueOf(Thread.currentThread().getContextClassLoader().getResource(""))).replaceAll("file:/", "").replaceAll("%20", " ").trim();
if(path.indexOf(":") != 1){
path = File.separator + path;
}
//path = "H:\\"; //当项目以jar、war包运行时路径改成实际硬盘位置
return path;
}
}