我的工程的结构:

使用 ReflectionDemo.class.getClassLoader().getResource("").getPath();
package com.itheima.reflection;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
public class ReflectionDemo {
public static void main(String[] args) throws IOException {
//1、 使用 Properties 类读取配置文件
Properties properties = new Properties();
String path = ReflectionDemo.class.getClassLoader().getResource("").getPath();
System.out.println(path);
//properties.load(new FileInputStream(path + "ref.properties"));
}
}
打印结果:
/D:/code/java/ProjectA/Test/test-demo/target/classes/
本文介绍如何在Maven工程中获取当前项目的类路径。通过示例代码展示了具体的操作步骤,帮助开发者解决相关问题。

1101

被折叠的 条评论
为什么被折叠?



