Combining paths using path resolution - Java File Path IO

Java examples for File Path IO:Path

Description

Combining paths using path resolution

Demo Code

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

public class Main {
  public static void main(String[] args) {
    Path rootPath = Paths.get("/home/docs");
    Path partialPath = Paths.get("users.txt");
    Path resolvedPath = rootPath.resolve(partialPath);
    System.out.println("rootPath: " + rootPath);
    System.out.println("partialPath: " + partialPath);
    System.out.println("resolvedPath: " + resolvedPath);
    System.out.println("Resolved absolute path: "
        + resolvedPath.toAbsolutePath());
  }/* ww w . j a v a 2 s . c o m*/
}

Related Tutorials