getPath(),getAbsolutePath(),getCanonicalPath()简介说明
下文笔者将通过示例的方式讲述getPath(),getAbsolutePath(),getCanonicalPath()的功能简介,如下所示
getPath(),getAbsolutePath(),getCanonicalPath()简介
getPath(): 直接返回构造 java.io.File 实例时使用的路径参数 getAbsolutePath(): 返回绝对路径,但不会处理相对路径符号 [.] 和 [..] getCanonicalPath(): 返回规范的绝对路径,即是绝对也是唯一
getPath(),getAbsolutePath(),getCanonicalPath()示例
package com.java265.other; import java.io.File; import java.io.IOException; public class Test21 { /** * java265.com * * @throws IOException */ public static void main(String[] args) throws IOException { File file = new File("./test.txt"); System.out.println(file.getPath()); System.out.println(file.getAbsolutePath()); System.out.println(file.getCanonicalPath()); } }

版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。