如何在项目的/ resources文件夹中获取文件的绝对路径
问题描述:
假设标准maven设置。
Assume standard maven setup.
在资源文件夹中说你有一个文件 abc
。
Say in your resources folder you have a file abc
.
在Java中,我怎样才能获得文件的绝对路径?
In Java, how can I get absolute path to the file please?
答
您可以创建文件
对象并使用 getAbsolutePath
方法:
You can create a File
object and use getAbsolutePath
method:
File file = new File("resources/abc.txt");
String absolutePath = file.getAbsolutePath();