java 求一函数获得 磁盘绝对路径

来源:百度知道 编辑:UC知道 时间:2024/06/25 22:49:50
例如 有个文件在这 ./java/1.jpg
但是 必须使用 绝对路径 例如 D:\1\java\1.jpg
前面这些路径又可能会变只能通过这个 相对路径
获得 在磁盘里的绝对路径
请问 有什么相关函数吗?

try java.io.File
{code}
public static void main(String[] a) {
String path = "/cmd/grep.exe";
File f = new File(path);
System.out.println("file f=" + f);
System.out.println("absolute path: " + f.getAbsolutePath());
}
{code}

output:
file f=\cmd\grep.exe
absolute path: C:\cmd\grep.exe

有这样的函数:
File类的getAbsolutePath() 方法。

你可以看看java.naming及它的扩展包。里面应该有你要的东西。