- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Absolute path of a file in Java
The method java.io.File.getAbsolutePath() is used to obtain the absolute path of a file in the form of a string. This method requires no parameters.
A program that demonstrates this is given as follows −
Example
import java.io.File; public class Demo { public static void main(String[] args) { File file = new File("C:" + File.separator + "jdk11.0.2" + File.separator, "demo1.java"); System.out.println("The absolute path name is: " + file.getAbsolutePath()); } }
The output of the above program is as follows −
Output
The absolute path name is:/C:/jdk11.0.2/demo1.java
Now let us understand the above program.
The absolute pathname of the file is obtained using the method java.io.File.getAbsolutePath() in the form of a string and is printed. A code snippet that demonstrates this is given as follows −
File file = new File("C:" + File.separator + "jdk11.0.2" + File.separator, "demo1.java"); System.out.println("The absolute path name is: " + file.getAbsolutePath());
- Related Articles
- Get the absolute path for the directory or file in Java
- Get an Absolute Filename Path from a Relative Filename Path in Java
- How to get the absolute path of a file using tkFileDialog(Tkinter)?
- Java Program to get the File object with the absolute path for the directory or file
- Get an Absolute Filename Path from a Relative Filename with Path in Java
- Golang program to get the name of the file from the absolute path
- C# Program to get the name of the file from the absolute path
- Get the name of the file and path in Java
- Get the Full Path of a File in Linux
- Get the path of the file selected in the JFileChooser component with Java
- How to get file name from a path in PHP?
- File Path with double slash in Java
- How to get the file name from the file path in Python?
- How to get left substring in MySQL from a column with file path? Display the entire file path string excluding the file name?
- Golang program to get the relative path from two absolute paths

Advertisements