Search This Blog

Wednesday, 12 February 2014

get absolute path of file in java

/* using java.io package for finding the absolute path of any path  */


import java.io.*;

class getPathOfFile
{
    public static void main(String[] args)
    {
        try
        {
            File f=new File("NewFileCreate.txt");
            if(!f.exists())
            {
                f.createNewFile();
                System.out.println("New File created...");
                System.out.println("Its absolute path is : "+f.getAbsolutePath());
            }
            else
            {
                System.out.println("File already exists...");
            }
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}

Output


New File created...
Its absolute path is : E:\Java_NetBeans\PROGRAMMING\JavaIO\NewFileCreate.txt

No comments:

Popular Posts