1.类路径 就是告诉JVM虚拟机从哪里去寻找要执行的类; (通俗的理解:就是存放class文件的目录) 2.如果不指定,则默认在 java 命令执行的目录下进行寻找。2.获取类路径的三种方式 2.1 代码
package com.northcastle.file;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class ApplicationFilePath {
public static void main(String[] args) throws IOException {
String classPath01 = ApplicationFilePath.class.getClassLoader().getResource("").getPath();
System.out.println("classPath01 == "+classPath01);
String classPath02 = Thread.currentThread().getContextClassLoader().getResource("").getPath();
System.out.println("classPath02 == "+classPath02);
String classPath03 = ApplicationFilePath.class.getResource("/").getPath();
System.out.println("classPath03 == "+classPath03);
}
}
2.2 执行结果
直接指向了编译后的class文件的目录
Congratulations!
You are one step closer to success!



