- 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 an Absolute Filename Path from a Relative Filename Path in Java
The method java.io.File.getAbsoluteFile() can be used to acquire the absolute filename path from a relative filename path in Java. This method requires no parameters. It returns the file that is defined by the path name.
A program that demonstrates this is given as follows −
Example
import java.io.File; public class Demo { public static void main(String[] argv) throws Exception { File file = new File("demo1.txt"); file = file.getAbsoluteFile(); System.out.println(file); } }
The output of the above program is as follows −
Output
c:\JavaProgram\demo1.txt
Now let us understand the above program.
The method java.io.File.getAbsoluteFile() is used to acquire the absolute filename path from a relative filename path. Then this is printed. A code snippet that demonstrates this is given as follows −
File file = new File("demo1.txt"); file = file.getAbsoluteFile(); System.out.println(file);
- Related Articles
- Get an Absolute Filename Path from a Relative Filename with Path in Java
- Get filename from string path in JavaScript?
- Java Program to remove file information from a filename returning only its path component
- Java Program to remove path information from a filename returning only its file component
- How to get the last dirname/filename in a file path argument in Bash?
- Golang program to get the relative path from two absolute paths
- Get Absolute path of a file in Java
- Get the absolute path for the directory or file in Java
- Get Boot path from RuntimeMXBean in Java
- Golang program to get the name of the file from the absolute path
- Make PHP pathinfo() return the correct filename if the filename is UTF-8
- How to get the absolute path of a file using tkFileDialog(Tkinter)?
- Unix filename pattern matching in Python
- Unix filename pattern matching in Python (fnmatch)
- Java Program to get the File object with the absolute path for the directory or file

Advertisements