Java中的相对路径 [英] relative path in Java
本文介绍了Java中的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我的程序驻留在
/ home / username / project / src / com / xyz /
..目标文件在..
/ home / username / project / secure /
'/ code>
解决方案
您电流路径。
currentPath = / home / username / project / src / com / xyz /;
/ home / username / project / secure /文件夹的相对路径为
relativePath = ../../../secure;
My program has to use certain files that reside in another directory. Right now I am using absolute path to specify the location of the files. But I know that the relative position of these files will remain the same compared to where my program is residing. How I can use relative path in Java to specify the location of these files?
For example my program is residing in
/home/username/project/src/com/xyz/
..and the target files are in..
/home/username/project/secure/
解决方案
Your current path.
currentPath= /home/username/project/src/com/xyz/;
Relative path to "/home/username/project/secure/" folder is
relativePath= ../../../secure;
这篇关于Java中的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文