如何在java类中获取javaWeb的根路径
展开全部
public static String getRealPath(Class clazz) {
String url = clazz.getResource("").getPath();
int displace = url.indexOf("WEB-INF");
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < displace - 1; i++) {
buffer.append(url.charAt(i));
}
return buffer.toString();
}
String url = clazz.getResource("").getPath();
int displace = url.indexOf("WEB-INF");
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < displace - 1; i++) {
buffer.append(url.charAt(i));
}
return buffer.toString();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询