如何根据包路径查找当前包的绝对路径(JAVA)

例如,目前有com.xxx.exception.errorcode这个路径的字符串

如何通过这个包路径来获取这个包的绝对路径(存放java文件的路径),查询这个包下有哪些java文件。

Class.class.getClass().getResource("/").getPath()获取根路径,再遍历文件

public static void main(String[] args) {
        String packageStr = Test2.class.getPackage().getName();
        System.out.println("packageStr:"+packageStr);
        Test2 test2 = new Test2();
        test2.getPath(packageStr);
    }

    public void getPath(String packageStr){
        String root = this.getClass().getResource("/").getPath();
        String path = root+packageStr.replace(".","/");
        File file = new File(path);
        File[] files= file.listFiles();
        for(File f:files){
            if(f.isFile()){
                System.out.println(f.getName());
            }
        }
    }
packageStr:com.tools
ApplicationStart.class
Test.class
Test2.class