package com.apach.demo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
@SpringBootTest
class DemoApplicationTests {
@Test
void contextLoads() {
}
public static void main(String[] args) throws IOException {
String path = DemoApplicationTests.class.getResource("").getPath();
String path1 = DemoApplicationTests.class.getResource("/").getPath();
String path2 = new File("/").getCanonicalPath();
String path7 = new File("").getCanonicalPath();
String path3 = DemoApplicationTests.class.getClassLoader().getResource("application.properties").getPath();
String path4 = Thread.currentThread().getContextClassLoader().getResource("").getPath();
String path5 = System.getProperty("user.dir");
String path6 = System.getProperty("java.class.path");
Properties pro = new Properties();
pro.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("application.properties"));
String name = pro.getProperty("user.name");
System.out.println("path = " + path); //path = /D:/work/demo/target/test-classes/com/apach/demo/
System.out.println("path1 = " + path1); //path1 = /D:/work/demo/target/test-classes/
System.out.println("path2 = " + path2); //path2 = D:\
System.out.println("path7 = " + path7); //path7 = D:\
System.out.println("path3 = " + path3); //path3 = /D:/work/demo/target/classes/application.properties
System.out.println("path4 = " + path4); //path4 = /D:/work/demo/target/test-classes/
System.out.println("path5 = " + path5); //path5 = D:\work\demo
System.out.println("path6 = " + path6); //path6 = ...
System.out.println("name = " + name); //name = aobama
}
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交