package pro;
import java.io.File;
public class GetPro {
public static void main(String[] args) {
GetPro gp = new GetPro();
gp.test();
}
public void test() {
String path=System.getProperty(“user.dir”);//项目根目录
File file = new File(path);
String parent = file.getParent();//项目所在目录
System. out .println( "fileB path: " + this.getClass().getResource( “/” ));
//输出结果:fileB path: file:/E:/%e5%b8%b8%e7%94%a8%e8%bd%af%e4%bb%b6/program/Test1/bin/
System. out .println( "fileA path: " + path);
//输出结果:fileA path: E:\常用软件\program\Test1
System. out .println( "fileC path: " + parent);
//输出结果:fileC path: E:\常用软件\program
}
}