Junit下获取src/test/resource路径

Junit下获取src/test/resource路径



package com.lmx.controller;

import org.junit.Test;

public class AdminControllerTest {

	@Test
	public void test() {

		String rootPath=this.getClass().getResource("/a.txt").getFile().toString();  
		System.out.println(rootPath);

		
		String rootPath1 = this.getClass().getResource("/a.txt").toString();
		System.out.println(rootPath1);
		
		
		String rootPath2 = this.getClass().getResource("/").toString();
		System.out.println(rootPath2);
		
		String rootPath3 = this.getClass().getResource("").toString();
		System.out.println(rootPath3);
		
		
		
		
	}

}

输出结果:

/E:/STSTest/ptest/target/test-classes/a.txt
file:/E:/STSTest/ptest/target/test-classes/a.txt
file:/E:/STSTest/ptest/target/test-classes/
file:/E:/STSTest/ptest/target/test-classes/com/lmx/controller/





总结不好多多担待,文章只单纯个人总结,如不好勿喷,技术有限,有错漏麻烦指正提出。本人QQ:373965070

猜你喜欢

转载自blog.csdn.net/liangmaoxuan/article/details/55676307
今日推荐