public class TestGetPath {
@Test
public void getCurrentPath(){
//取得根目录路径
//getClass().getResource() 方法获得相对路径( 此方法在jar包中无效。返回的内容最后包含/)
///E:/myEclipse_workspace/Hxzs/build/classes/
String rootPath = getClass().getResource("/").getFile().toString();
System.out.println(rootPath);
//当前目录路径
///E:/myEclipse_workspace/Hxzs/build/classes/com/honszeal/test/
///E:/myEclipse_workspace/Hxzs/build/classes/com/honszeal/test/
///E:/myEclipse_workspace/Hxzs/build/classes/com/honszeal/
String currentPath1 = getClass().getResource(".").getFile().toString();
System.out.println(currentPath1);
String currentPath2 = getClass().getResource("").getFile().toString();
System.out.println(currentPath1);
//当前目录的上级目录
String parentPath = getClass().getResource("../").getFile().toString();
System.out.println(parentPath);
//利用System.getProperty()函数获取当前路径,得到项目文件夹的根目录,不带/
//E:\myEclipse_workspace\Hxzs
System.out.println(System.getProperty("user.dir"));
}