Path resolveSibling() method in Java with Examples Last Updated : 11 Mar, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report resolveSibling() method of java.nio.file.Path used to resolve the given path against this path's parent path.. There are two types of resolveSibling() methods. resolveSibling(Path other) method of java.nio.file.Path used to resolve the given path as parameter against this path's parent path. This is very useful where a file name needs to be replaced with another file name. For example, suppose that the name separator is "/" and a path represents "drive/newFile/spring", then invoking this method with the Path "plugin" will result in the Path "drive/newFile/plugin". If this path does not have a parent path or other is absolute, then this method returns others. If other is an empty path then this method returns this path's parent, or where this path doesn't have a parent, the empty path. Syntax: 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: resolveSibling(String other) method of java.nio.file.Path used to converts a given path string which we passed as parameter to a Path and resolves it against this path's parent path in exact same manner as specified by the resolveSibling method. Syntax: 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: References: https://docs.oracle.com/javase/10/docs/api/java/nio/file/Path.html#resolveSibling(java.lang.String) https://docs.oracle.com/javase/10/docs/api/java/nio/file/Path.html#resolveSibling(java.nio.file.Path) Comment More infoAdvertise with us Next Article Path toFile() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-Path java.nio.file package Practice Tags : Java Similar Reads Path resolve() method in Java with Examples resolve() method of java.nio.file.Path used to resolve the given path against this path. There are two types of resolve() methods. resolve(String other) method of java.nio.file.Path used to converts a given path string to a Path and resolves it against this Path in the exact same manner as specified 3 min read Path toString() method in Java with Examples The Java Path interface was added to Java NIO in Java 7. toString() method of java.nio.file.Path used to return the string representation of this path. If this path was created by converting a path string using the getPath method then the path string returned by this method may differ from the origi 2 min read Path relativize() method in Java with Examples The relativize(Path other) method of java.nio.file.Path used to create a relative path between this path and a given path as a parameter. Relativization is the inverse of resolution. This method creates a relative path that when resolved against this path object, yields a path that helps us to locat 2 min read Path toFile() method in Java with Examples The toFile() method of java.nio.file.Path interface used to return a java.io.File object representing this path object. if this Path is associated with the default provider, then this method returns a java.io.File object constructed with the String representation of this path. If this path was creat 2 min read Path toFile() method in Java with Examples The toFile() method of java.nio.file.Path interface used to return a java.io.File object representing this path object. if this Path is associated with the default provider, then this method returns a java.io.File object constructed with the String representation of this path. If this path was creat 2 min read Path toUri() method in Java with Examples The toUri() method of java.nio.file.Path interface used to return a URI to represent this path. This method converts this path into an absolute URI with a scheme equal to the URI scheme that identifies the provider. The exact form of the scheme-specific part is highly provider dependent. In the scen 2 min read Like