Java.io.File.getAbsoluteFile() Method
Advertisements
Description
The java.io.File.getAbsoluteFile() method returns the absolute form of this abstract pathname.
Declaration
Following is the declaration for java.io.File.getAbsoluteFile() method:
public File getAbsoluteFile()
Parameters
NA
Return Value
The method returns the same file defined by the absolute abstract pathname.
Exception
SecurityException -- if a system property value can not be accessed.
Example
The following example shows the usage of java.io.File.getAbsoluteFile() method.
package com.tutorialspoint;
import java.io.File;
public class FileDemo {
public static void main(String[] args) {
File f = null;
File f1 = null;
String path = "";
boolean bool = false;
try{
// create new files
f = new File("test.txt");
// create new file in the system
f.createNewFile();
// create new file object from the absolute path
f1 = f.getAbsoluteFile();
// returns true if the file exists
bool = f1.exists();
// returns absolute pathname
path = f1.getAbsolutePath();
// if file exists
if(bool)
{
// prints
System.out.print(path+" Exists? "+ bool);
}
}catch(Exception e){
// if any error occurs
e.printStackTrace();
}
}
}
Let us compile and run the above program, this will produce the following result:
D:\EclipseAndroid\IO\BufferedInputStream\test.txt Exists? true