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.