import org.junit.Test;
import org.springframework.util.ResourceUtils;
import java.io.File;
import java.io.IOException;
public class TestPath {
@Test
public void test() throws IOException {
//获取项目下target下的路径
String path1 = Thread.currentThread().getContextClassLoader().getResource("").getPath();
String path2 = ResourceUtils.getURL("classpath:").getPath();
//获取项目下的路径(加 String relate = "\\src\\main\\resources";可以得到resources下文件路径)
String path3 = System.getProperty("user.dir");
File directory = new File(".");
String root = directory.getCanonicalPath();
System.out.println(path1);
System.out.println(path2);
System.out.println(path3);
System.out.println(root);
}
}
SpringBoot获取文件路径
最新推荐文章于 2024-05-07 16:44:22 发布