1.类路径 就是告诉JVM虚拟机从哪里去寻找要执行的类; (通俗的理解:就是存放class文件的目录) 2.如果不指定,则默认在 java 命令执行的目录下进行寻找。
package com.northcastle.file; import java.io.IOException; import java.io.InputStream; import java.util.Properties; /** * author : northcastle * createTime:2022/1/10 * 本案例进行探究一下 java中的文件路径的问题 */ public class ApplicationFilePath { public static void main(String[] args) throws IOException { /** * 4.获取classpath的路径 * 前面有个“/” * 下面的三种方式是一样的,返回的是 classPath 的路径 * 这个目录下的内容,就是编译过后的 class文件的存放的目录 * */ 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); } }
直接指向了编译后的class文件的目录
Congratulations!
You are one step closer to success!