One. Get the path:
In a separate Java class, the absolute path is obtained according to the doc block of the Java.io.File, which indicates that the directory represented by the new File ("/") is: System.getproperty ("User.dir") by default.
The program obtains the current path of the execution class:
system.out.println ("1:" + test2. Class . GetResource (" "2:" + Test2. class . getClassLoader (). GetResource (" "3:" + Test2. class . getClassLoader (). GetResource (" "4:" +classloader.getsystemresource (""));
output is:
1:file:/c:/users/administrator/git/sourcecontrol/demo1/target/test-classes/demo1/
2:file:/c:/users/administrator/git/sourcecontrol/demo1/target/test-classes/
3:/c:/users/administrator/git/sourcecontrol/demo1/target/test-classes/
4:file:/c:/users/administrator/git/sourcecontrol/demo1/target/test-classes/
Summary of Java Path class problems