Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在spring中从jar读取时未找到文件异常?_Java_Spring - Fatal编程技术网

Java 在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());

我正在使用spring,我想从jar文件中读取文件名,但是我得到了
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程序”?