Convert a relative path into an absolute path in Java
Description
The following code shows how to convert a relative path into an absolute path.
Example
import java.net.URI;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
/*from w w w.j av a 2s .c om*/
public class Main {
public static void main(String[] args) throws Exception {
Path path = Paths.get("/home", "docs", "users.txt");
System.out.println("Absolute path: " + path.toAbsolutePath());
}
}
The code above generates the following result.