Convert a Path to a String - Java File Path IO

Java examples for File Path IO:Path


String conversion of a path can be achieved by the toString() method:

Demo Code

import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
  public static void main(String[] args) {
    Path path = Paths.get("/folder1/folder2/folder4", "test.txt");

    // convert path to String
    String path_to_string = path.toString();
    System.out.println("Path to String: " + path_to_string);
  }/*from   w  w w.ja  v  a2s .c o m*/


Related Tutorials