您的位置:首页 > 编程语言 > Java开发

java中的各种路径的获取方式

2014-07-24 18:22 141 查看
@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走运行一下就可以了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: