import java.io.File;
public class FileDemo {
public static void main(String[] args) {
File file = new File("d:");
System.out.println(file.getAbsolutePath());
file = new File("d:\\");
System.out.println(file.getAbsolutePath());
file = new File("c:");
System.out.println(file.getAbsolutePath());
}
}
//输出
d:\workspace\eclipse3.4_RCP\project_FileWatcher
d:\
c:\
希望知道为什么会出现这种情况
我做了个实验:把.class文件放在不同的目录下,比如我放在E:盘下,会输出:
d:\
d:\
c:\Documnet and Settings.....
如果我把.class放在C盘下面,得到结果是:
d:\
d:\
c:\
这个问题跟底层内容有关吧
楼主,你配置了jdk的path没? 你的jdk安装在哪个目录下啊,我运行了下,输出没有问题啊,
[code="java"]
File file = new File("d:");
System.out.println(file.getAbsolutePath());
file = new File("d:\\");
System.out.println(file.getAbsolutePath());
file = new File("c:");
System.out.println(file.getAbsolutePath());
[/code]
output:
[code="java"]
d:\
d:\
c:\
[/code]
getAbsolutePath
public String getAbsolutePath()返回抽象路径名的绝对路径名字符串。
如果此抽象路径名已经是绝对路径名,则返回该路径名字符串,这与 getPath() 方法一样。如果此抽象路径名是空的抽象路径名,则返回当前用户目录的路径名字符串,该目录由系统属性 user.dir 指定。否则,[color=darkred]使用与系统有关的方式分析此路径名[/color]。在 UNIX 系统上,通过根据当前用户目录分析某一相对路径名,可使该路径名成为绝对路径名。在 Microsoft Windows 系统上,通过由路径名指定的当前驱动器目录(如果有)来分析某一相对路径名,可使该路径名成为绝对路径名;否则,可以根据当前用户目录来分析它。
如果目录不存在。目录由系统属性 user.dir 指定