如果字符串pathname用于创建File对象,则getPath()只返回pathname参数,例如File file = new File(pathname)构造参数pathname是怎么样,getPath()就返回怎么的字符串。如果URI用作参数,则它将删除协议并返回文件名。 getAbsolutePath():此文件路径方法返回文件的绝对路径。如果使用绝对路径名创建File对象,则只返回路径名。
2、getAbsolutePath(): 返回绝对路径,但不会处理“.”和“..”的情况 3、getCanonicalPath(): 返回的是规范化的绝对路径,相当于将getAbsolutePath()中的“.”和“..”解析成对应的正确的路径 第一个例子:(使用:“.\\src\\test.txt”一个点路径) 1 2 3 4 5 6 7 8 9 10 11 File file =newFile...
getCanonicalPath(): 返回的是规范化的绝对路径,相当于将getAbsolutePath()中的“.”和“..”解析成对应的正确的路径 举例如下: File file =newFile(".\\test.txt"); System.out.println(file.getPath()); System.out.println(file.getAbsolutePath()); System.out.println(file.getCanonicalPath()); 返...
If this abstract pathname is already absolute, then the pathname string is simply returned as if by thegetPath()method. If this abstract pathname is the empty abstract pathname then the pathname string of the current user directory, which is named by the system propertyuser.dir, is returned. ...
最近在做安卓作业的时候遇到了getCanonicalPath,遂上网查了一番资料 来看一个DEMO吧: public class test_path { public static void main(String[] args) throws IOException{ File file1 = new File("..\\test1.txt"); File file2 = new File("D:\\workspace\\test\\test1.txt"); ...
getAbsolutePath()得到的是全路径 如果构造的时候就是全路径那直接返回全路径 如果构造的时候试相对路径,返回当前目录的路径+构造file时候的路径 2,getAbsolutePath()和getCanonicalPath()的不同 publicstaticvoidtest2()throwsException { Filefile=newFile("..\\src\\test1.txt"); ...
3、getCanonicalPath(): 返回的是规范化的绝对路径,相当于将getAbsolutePath()中的“.”和“..”解析成对应的正确的路径 第一个例子:(使用:“.\\src\\test.txt”一个点路径) File file = new File(".\\src\\test.txt"); System.out.println(file.getPath()); ...
getPath()、getAbsolutePath()和getCanonicalPath()有什么不同?ENgetPath()返回用于创建File对象的路径...
getAbsolutePath() 得到绝对路径、全路径。getpath 得到缩写的路径,根据当前目录位置可以缩写路径。得到相对路径。getCanonicalPath() 得到标准路径,将统一平台间的路径写法差异。前面
getCanonicalPath public String getCanonicalPath()throws IOException 返回此抽象路径名的规范路径名字符串。规范路径名是绝对路径名,并且是惟一的。规范路径名的准确定义与系统有关。如有必要,此方法首先将路径名转换为绝对路径名,这与调用 getAbsolutePath() 方法的效果一样,然后用与系统相关的方式...