美文网首页Android
Android three different ways to

Android three different ways to

作者: JaedenKil | 来源:发表于2017-10-09 17:47 被阅读5次

There are there different ways to get a file path :

File.getPath()
File.getAbsolutePath()
File.getCanonicalPath()

They adapt to different situations, for example :

File file = new File("./test.txt");
System.out.println(file.getPath());
System.out.println(file.getAbsolutePath());
System.out.println(file.getCanonicalPath());

This prints :

./test.txt
/home/XXX/IdeaProjects/LittlePractise/./test.txt
/home/XXX/IdeaProjects/LittlePractise/test.txt

So when I need to get the path of a file, File.getCanonicalPath() should be my first choice.

相关文章

网友评论

    本文标题:Android three different ways to

    本文链接:https://www.haomeiwen.com/subject/mlmpyxtx.html