Find the Absolute path and relative path in Java

Description

The following code shows how to find the Absolute path and relative path.

Example


//  w w  w . ja  v  a  2  s.  co  m
import java.io.File;

public class Main {

  public static void main(String[] args) {

    File absolute = new File("/public/html/javafaq/index.html");
    File relative = new File("html/javafaq/index.html");

    System.out.println("absolute: ");
    System.out.println(absolute.getName());
    System.out.println(absolute.getPath());

    System.out.println("relative: ");
    System.out.println(relative.getName());
    System.out.println(relative.getPath());
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip