JAVA I/O File 种学习之getCanonicalFile
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,但实际中没有这个目录,抽象的么。
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,但实际中没有这个目录,抽象的么。