Java File.toPath() method example

 Posted On  | Pooja Lakkihal 

In this java tutorial, You will learn how to get the path constructed from this abstract file path. Java File.toPath() method returns a Path constructed from this abstract path.

Returns a java.nio.file.Path object constructed from the this abstract path. The resulting Path is associated with the default-filesystem.


public Path toPath()


A Path constructed from this abstract path.


InvalidPathException - if a Path object cannot be constructed from the abstract path (see FileSystem.getPath).

Java File toPath() example

  • Create file instance new File("c:\\technicalkeeda\\test.txt");
  • file.toPath() It will get the path of file.
package com.technicalkeeda;


public class App {

    public static void main(String[] args) {

        File file = new File("c:\\technicalkeeda\\test.txt");

        System.out.println("File Path is :- " + file.toPath());



File Path is :- c:\technicalkeeda\test.txt

© 2018

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0440 seconds.