如何在项目的/ resources文件夹中获取文件的绝对路径 [英] How to get absolute path to file in /resources folder in your project
本文介绍了如何在项目的/ 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();
这篇关于如何在项目的/ resources文件夹中获取文件的绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文