Getting an Absolute Filename Path from a Relative Filename Path - Java File Path IO

Java examples for File Path IO:Path

Description

Getting an Absolute Filename Path from a Relative Filename Path

Demo Code

import java.io.File;

public class Main {
  public void m() {
    File file = new File("filename.txt");
    file = file.getAbsoluteFile(); // c:\temp\filename.txt

    file = new File("dir" + File.separatorChar + "filename.txt");
    file = file.getAbsoluteFile(); // c:\temp\dir\filename.txt

    file = new File(".." + File.separatorChar + "filename.txt");
    file = file.getAbsoluteFile(); // c:\temp\..\filename.txt

    // Note that filename.txt does not need to exist
  }//from   w  w  w .ja  va2  s.com
}

Related Tutorials