Java I/O How to - Convert a relative path into an absolute path


We would like to know how to convert a relative path into an absolute path.


import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
/*from   www .ja  v a 2  m*/
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.