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());
  }//  w  w w  .  ja  v a 2  s .  c  o m
}

Result


Related Tutorials