Resolve sibling Path in Java

Description

The following code shows how to resolve sibling Path.

Example


import java.nio.file.Path;
import java.nio.file.Paths;
/*from   w  w w . j  a va 2 s.co  m*/
public class Main {

  public static void main(String[] args) {
    Path rootPath = Paths.get("/home/docs");
    Path resolvedPath = rootPath.resolve("backup/users.txt");

    resolvedPath = rootPath.resolve("tmp/A.mp3");
    System.out.println("rootPath: " + rootPath);
    System.out.println("resolvedPath: " + resolvedPath);
    System.out.println();

    resolvedPath = rootPath.resolveSibling("tmp/A.mp3");
    System.out.println("rootPath: " + rootPath);
    System.out.println("resolvedPath: " + 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