by @kodeazy

Java How to convert file object to path object?

Home » java » Java How to convert file object to path object?
  • In this blog we will be discusing on how to convert File object to Path object in java.
  • To convert file object to path object we use toPath() function by importing import java.nio.file.Path class.
  • Below is the syntax.

    Path path=myObj.toPath();

    Below is the sample Program to convert File object to Path object.

    import java.io.File;
    import java.io.IOException;
    import java.nio.file.Path;
    class FileExample{
    public static void main(String args[]) throws Exception{
    	 File myObj = new File("fileExample.txt");
    	 Path path=myObj.toPath();
    	}
    }