1. Introduction
In this article, we are going to present how to convert File
into Path
in Java. A Path is an object that may be used to locate a file in a file system. This article will cover the two most common solutions from Java 7+.
2. Convert File
to Path
using toPath()
method
Path
object was introduced in Java 7. In this version of JDK, we can get the Path
using the File.toPath()
method.
3. Convert File
to Path
using Paths
object
The Paths
object is a dedicated class that consists exclusively of static methods that return a Path
.
In the following example code we used Paths.get(...)
method to convert File
to Path
:
4. Conclusion
In this article, we presented ways to convert File
to Path
. We use the Path
object to locate a file in the file system. Bear in mind that Path
is only available for Java 7+ programs.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}