先上一段代码
public static void main(String[] args) {
URL resource = WordTest.class.getResource("/hello1.ftl");
// URL resource = WordTest.class.getResource("hello1.ftl"); 错误的写法
System.out.println(resource.getPath());
URL resource1 = WordTest.class.getClassLoader().getResource("hello1.ftl");
// URL resource1 = WordTest.class.getClassLoader().getResource("/hello1.ftl"); 错误的写法
System.out.println(resource1.getPath());
}
复制代码
目录结构
以前还真不知道这两种写法的区别,今天学习了~