Combine paths using path resolution in Java

Description

The following code shows how to combine paths using path resolution.

Example


import java.nio.file.Path;
import java.nio.file.Paths;
//from   w w w .  jav a  2 s .c om
public class Main {

  public static void main(String[] args) {
    Path rootPath = Paths.get("c:/home/docs");
    System.out.println(rootPath);
    Path partialPath = Paths.get("users.txt");
    System.out.println(partialPath);
    Path resolvedPath = rootPath.resolve(partialPath);
    System.out.println(resolvedPath);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip