![]() |
In Java, we can convert a String representation of a file or directory path into a path object using the Paths utility class. It is a part of the java.nio.file package. The Paths class provides a method called get(String file path location) that converts a sequence of strings representing a path into a Path object. In this article, we will learn How to Convert a String to a Path in Java. Import these classes: import java.nio.file.Paths; Program to Convert a String to a Path in JavaWe can use the Paths.get() method to convert the string to a path. Java
Output
C:/Users/Desktop/New Folder Explanation of the Program:
If we do not have the entire path in string, we can provide it piece by piece, or folder by folder. By using the Paths.get() method and pass each folder as a separate parameter. Java
Output
C:/Users/Desktop/New Folder Explanation of the Program:In the above program,
|
Reffered: https://www.geeksforgeeks.org
Java Programs |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |