java获取项目绝对路径
01 |
public static void main(String[] args) {
|
02 |
//获取是项目的绝对路径
|
03 |
System.out.println(System.getProperty( "user.dir" ));
|
04 |
System.out.println( new File( "" ).getAbsolutePath());
|
05 |
//获取到clsspath绝对路径
|
06 |
System.out.println(ServerDemo. class .getResource( "/" ));
|
07 |
System.out.println(Thread.currentThread().getContextClassLoader().getResource( "" ));
|
08 |
System.out.println(ServerDemo. class .getClassLoader().getResource( "" ));
|
09 |
10 |
} |