 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Specify a path for a file or a directory in Java
The path for a file can be obtained using the method java.io.File.getPath(). This method returns the abstract pathname in the form of a pathname string and it 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("Path = " + file.getPath());    } } The output of the above program is as follows −
Output
Path = C:/jdk11.0.2/demo1.java
Now let us understand the above program.
The path name of the file is printed using the method getPath(). 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("Path = " + file.getPath());Advertisements
 