Convert a Relative Path to an Absolute Path - Java File Path IO

Java examples for File Path IO:Path

Introduction

Obtaining an absolute path from a relative one.

Demo Code

import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
  public static void main(String[] args) {
    Path path = Paths.get("/folder1/folder2/folder4", "test.txt");

    //convert relative path to absolute path
    Path path_to_absolute_path = path.toAbsolutePath();
    System.out.println("Path to absolute path: " + path_to_absolute_path.toString());
  }/*ww w  .  ja v a 2s .com*/
}

Result


Related Tutorials