我正在使用 Camel 创建一些路线。
我在资源文件夹中有一个文件,我只想要文件路径+名称。不是内容。
当我使用时:
from(URI)
.log("resource:classpath:llave.txt")
我得到了 llave.txt 的内容,但我需要类似的东西
C:\something\llave.txt
谢谢!!
为清楚起见进行编辑:我不需要来自文件端点的文件信息(另外,使用文件语言或交换 header 很容易获取该信息)。
我需要位于项目的资源文件夹中的文件的信息。
最佳答案
获取文件:
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("llave.txt").getFile());
获取路径:
//full path ( including the file )
String absolutePath = file.getAbsolutePath();
// path only
String filePath = absolutePath.
substring(0, absolutePath.lastIndexOf(File.separator));
关于java - 从资源中获取文件名(带路径),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30875148/