Last Updated : 11 Mar, 2022
resolveSibling()method of
java.nio.file.Pathused to resolve the given path against this path's parent path.. There are two types of resolveSibling() methods.
default Path resolveSibling(Path other)Parameters: This method accepts a single parameter other which is the path to resolve against this path's parent. Return value: This method return the resulting path. Below programs illustrate resolveSibling(Path other) method: Program 1: Java
// Java program to demonstrate
// Path.resolveSibling(Path other) method
import java.nio.file.Path;
import java.nio.file.Paths;
public class GFG {
public static void main(String[] args)
{
// create object of Path
Path path
= Paths.get("drive\\temp\\Spring");
// create an object of Path
// to pass to resolve method
Path path2
= Paths.get("programs\\workspace");
// call resolveSibling()
// to create resolved Path
// on parent of path object
Path resolvedPath
= path.resolveSibling(path2);
// print result
System.out.println("Resolved Path "
+ "of path's parent:"
+ resolvedPath);
}
}
Output:default Path resolveSibling(String other)Parameters: This method accepts a single parameter other which is the path string to resolve against this path's parent. Return value: This method returns the resulting path. Exception: This method throws InvalidPathException if the path string cannot be converted to a Path. Below programs illustrate resolveSibling(String other) method: Program 1: Java
// Java program to demonstrate
// Path.resolveSibling(String other) method
import java.nio.file.Path;
import java.nio.file.Paths;
public class GFG {
public static void main(String[] args)
{
// create an object of Path
Path path
= Paths.get("drive\\temp\\Spring");
// create a string object
String passedPath = "drive";
// call resolveSibling()
// to create resolved Path
// on parent of path object
Path resolvedPath
= path.resolveSibling(passedPath);
// print result
System.out.println("Resolved Path of "
+ "path's parent:"
+ resolvedPath);
}
}
Output:RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4