Java File getPath() Method
Example
Get the path of a file:
import java.io.File;
public class Main {
public static void main(String[] args) {
File myFile = new File("filename.txt");
System.out.println(myFile.getPath());
}
}
Definition and Usage
The getPath() method returns the path of the file, as you wrote it when you created the File object.
The path is not changed to a full path. Use the getAbsolutePath() method to get the full path.
Note: On Windows, Java changes forward slashes (/) in the path to backslashes (\).
Syntax
public String getPath()
Parameter Values
None.
Technical Details
| Returns: | The path, as a String. |
|---|
Related Pages
❮ File Methods