先看一个示例:
结果是:
似乎 getPath() 与 getAbsolutePath() 并没有区别,但是这只是在这种情况下,我们继续看:
File file = new File(getFilesDir().getPath());
以上代码是没有问题的,但是如果换成 getAbsolutePath() 就运行不起,还真奇了怪了。
有网友用 new File() 测试,具体是:如果 new File() 的参数是全路径,则 getPath()、getAbsolutePath() 没有区别,如果 new File() 的参数是相对路径,则 getPath() 返回的是相对路径(也就是参数),而 getAbsolutePath() 是转换成全路径后的全路径。