假设程序信息未知,获取当前程序的路径信息和文件名

我想问下,如果获取当前程序所在的目录信息。
在网上查了,很久,知道怎么获得文件名,也能获得项目路径,可是怎么获得项目到文件的路径。

这是我试了很久后的代码,我明明是在src/main/java/homework/day03/Test03这里运行的,可是结果为什么会返回C:\Users\tarena\Desktop\JSD2207SE\target\classes\homework\day03这个路径给我,我就想通过代码返回src/main/java/homework/day03/Test03这一串路径来。主要我想写一个可以移植的代码,只要复制这一段,无论放到哪个文件,都能够获得这个文件的路径信息和文件名

public class Test03 {
    private void getJarFileName() {
        String myClassName = this.getClass().getName();
        System.out.println(myClassName);
    }private void a(){
//        File f = new File(this.getClass().getResource("/").getPath());
        File f2 = new File(this.getClass().getResource("").getPath());
        System.out.println(f2);
    }

    public static void main(String[] args) {
        Test03 t = new Test03();

        t.getJarFileName();
        t.a();
        System.out.println(System.getProperty("user.dir"));

img

因为真正的类路径就是target下而不是在src下