//获取包的绝对路径
String packagePath = "com.csdn";
//com.csdn 转为 com/csdn
String packagePath = basePackage.replaceAll("\\.", "\\\\");
Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(packagePath);
while (resources.hasMoreElements()) {
//获取绝对路径
URL url = resources.nextElement();
String filePath = URLDecoder.decode(url.getFile(), "utf-8");//转码
//获取前部分路径
String substring = filePath.substring(0, filePath.length() - packagePath.length());
System.out.println(substring);
}
java 获取包的绝对路径
最新推荐文章于 2024-08-23 15:54:50 发布