How do I get the absolute path of a file?

Bookmark this example!  
Category: java.io, viewed: 1408 time(s).
 
package org.kodejava.sample.java.io;
 
import java.io.File;
 
public class AbsolutePathExample
{
    public static void main(String[] args)
    {
        // Create an instance of File called file.
        File file = new File("JavaProgrammingBook.pdf");
 
        // Now we want to know where is exactly this file is
        // located in our file system. To do this we can use
        // the getAbsolutePath() method of the File class.
        String absolutePath = file.getAbsolutePath();
 
        // Print out the JavaProgrammingBook.pdf location to
        // the console.
        System.out.println("AbsolutePath = " + absolutePath);
    }
}
 
 

Here is the result of the program:

AbsolutePath = D:\Data\Projects\2005\kodejava-samples\JavaProgrammingBook.pdf
Can't find what you are looking for? Join our FORUMS and ask some questions!

Most Viewed Examples

Latest Code Examples

100 Top & Latest


Locations of visitors to this page
eXTReMe Tracker
visitor stats
Get Chitika Premium