xxx.class.getClassLoader().getResource("")获取是什么路径
答
获取的是class文件的根目录路径,看以下例子:
String file = SysAdminController.class.getClassLoader().getResource("").getFile();
file值(不是运行jar包):/F:/jianzhi/idea_items/fish_port_admin/common-bx-auth/target/classes/
file值(运行jar包):/F:/jianzhi/idea_items/fish_port_admin/common-bx-auth/target/common-bx-auth-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/
String file = SysAdminController.class.getClassLoader().getResource("application.yml").getFile();
file值(不是运行jar包):/F:/jianzhi/idea_items/fish_port_admin/common-bx-auth/target/classes/application.yml
file值(运行jar包):/F:/jianzhi/idea_items/fish_port_admin/common-bx-auth/target/common-bx-auth-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/application.yml
注意:String file = SysAdminController.class.getClassLoader().getResource("/").getFile();//报错不能写“/”