import java.io.File;
import java.io.IOException;
import java.net.URL;
public class MyUrlDemo {
public static void main(String[] args) {
MyUrlDemo muDemo = new MyUrlDemo();
try {
muDemo.showURL();
} catch (IOException e) {
e.printStackTrace();
}
}
public void showURL() throws IOException {
File f = new File(this.getClass().getResource("/").getPath());
System.out.println(f);
File f2 = new File(this.getClass().getResource("").getPath());
System.out.println(f2);
File directory = new File("");
String courseFile = directory.getCanonicalPath();
System.out.println(courseFile);
URL xmlpath = this.getClass().getClassLoader().getResource("");
System.out.println(xmlpath);
System.out.println(System.getProperty("user.dir"));
System.out.println(System.getProperty("java.class.path"));
}
}
转载:https://www.cnblogs.com/franson-2016/p/6163422.html