ass*_*ias 14
你可以使用Pathapi:
Path p = Paths.get(yourFileNameUri);
Path folder = p.getParent();
Run Code Online (Sandbox Code Playgroud)
jlo*_*rdo 14
查看java.io.File类中的方法:
File file = new File("yourfileName");
String path = file.getAbsolutePath();
Run Code Online (Sandbox Code Playgroud)
我不确定我是否完全理解你,但是如果你希望获得绝对文件路径,只要你知道相对文件名,你就可以这样做:
System.out.println("File path: " + new File("Your file name").getAbsolutePath());
Run Code Online (Sandbox Code Playgroud)
File类还有几个你可能会觉得有用的方法.
使用“文件”类的正确解决方案以获取目录 - 文件的“路径”:
String path = new File("C:\\Temp\\your directory\\yourfile.txt").getParent();
Run Code Online (Sandbox Code Playgroud)
这将返回:
path = "C:\\Temp\\your directory"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
96523 次 |
| 最近记录: |