Java 在spring中从jar读取时未找到文件异常?
我正在使用spring,我想从jar文件中读取文件名,但是我得到了Java 在spring中从jar读取时未找到文件异常?,java,spring,Java,Spring,我正在使用spring,我想从jar文件中读取文件名,但是我得到了FileNotFoundException。任何人帮助我,请检查我下面的代码 ClassPathResource classPathResource = new ClassPathResource("test.txt"); System.out.println(classPathResource.getPath()); System.out.println(classPathResource.getURI());
FileNotFoundException
。任何人帮助我,请检查我下面的代码
ClassPathResource classPathResource = new ClassPathResource("test.txt");
System.out.println(classPathResource.getPath());
System.out.println(classPathResource.getURI());
System.out.println(classPathResource.getURL().getPath());
System.out.println(classPathResource.getURI().getPath());
但是当我像下面这样写的时候
System.out.println(classPathResource.getFile().getCanonicalPath());
System.out.println(classPathResource.getFile().getPath());
上面的两行代码引发了异常,但当我使用普通java程序时,一切都很正常。有帮助吗?也许在打包程序时检查文件的位置。什么是“普通java程序”?