首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

JAVA I/O File 种学习之getCanonicalFile

2012-11-05 
JAVA I/O File 类学习之getCanonicalFileFile.getCanonicalFile()0推荐JDK中写着:public File getCanonica

JAVA I/O File 类学习之getCanonicalFile
File.getCanonicalFile()0推荐JDK中写着:

public File getCanonicalFile()
                      throws IOException
返回此抽象路径名的规范形式。等同于 new File(this.getCanonicalPath()())。
测试类写于F:\Eclipse\rcp\workspace\crescent项目中,

public static void main(String[] args) {
   File file = new File("");
   try {
    File file2 = file.getCanonicalFile();
    System.out.println(file2.getPath());
   } catch (IOException e) {
    e.printStackTrace();
   }
}

运行结果为:

F:\Eclipse\rcp\workspace\crescent
看样子为项目的根目录,当把红色一行换成   File file = new File("allen");

结果为:F:\Eclipse\rcp\workspace\crescent\allen,但实际中没有这个目录,抽象的么。

热点排行