@Test
public void testb() throws IOException{
//getLog4jProties();
/*******获取类加载的根路径************/
//E:/workspace/Myeclipse10/workspace/springtest/WebRoot/WEB-INF/classes/
System.out.println(this.getClass().getResource("/").getPath());
/**********获取类加载的路径************************/
///E:/workspace/Myeclipse10/workspace/springtest/WebRoot/WEB-INF/classes/com/test/initmethod/
System.out.println(this.getClass().getResource("").getPath());
/**********获取src下的文件路径************************/
///E:/workspace/Myeclipse10/workspace/springtest/WebRoot/WEB-INF/classes/log4j.properties
System.out.println(this.getClass().getResource("/log4j.properties").getPath());
/***********获取项目路径***********************/
//E:\workspace\Myeclipse10\workspace\springtest
File dict = new File("");
System.out.println(dict.getCanonicalPath());
/***********获取磁盘根路径***********************/
//E:\
File dict1 = new File("/");
System.out.println(dict1.getCanonicalPath());
/**********************************/
System.out.println(this.getClass().getClassLoader().getResource("/"));
/***********获取项目路径************************/
//E:\workspace\Myeclipse10\workspace\springtest
System.out.println(System.getProperty("user.dir"));
/***********获取classpath的所有路径*************************/
System.out.println(System.getProperty("java.class.path"));
}
copy走运行一下就可以了
java中的各种路径的获取方式
最新推荐文章于 2022-08-11 07:10:13 发布