Comparing getPath(), getAbsolutePath(), and getCanonicalPath() in Java
1. Overview The java.io.File class has three methods — getPath() , getAbsolutePath() and getCanonicalPath() — to obtain the filesystem path. In this article, we'll have a quick look at the differences between them and discuss a use case where you may choose to use one over the others. 2. Method Definitions and Examples Let's start by going over the definitions of the three methods, along with examples based on having the following directory structure present in the user's home directory: |-- baeldung |-- baeldung.txt |-- foo | |-- foo-one.txt | \-- foo-two.txt \-- bar |-- bar-one.txt |-- bar