Java.io.File.isAbsolute() Method
Advertisements
Description
The java.io.File.isAbsolute() checks whether this abstract pathname is absolute.
Declaration
Following is the declaration for java.io.File.isAbsolute() method:
public boolean isAbsolute()
Parameters
NA
Return Value
The method returns true if this abstract pathname is absolute, else the method returns false.
Exception
NA
Example
The following example shows the usage of java.io.File.isAbsolute() method.
package com.tutorialspoint;
import java.io.File;
public class FileDemo {
public static void main(String[] args) {
File f = null;
String path;
boolean bool = false;
try{
// create new file
f = new File("C:\\test.txt");
// true if the file path is absolute, else false
bool = f.isAbsolute();
// get the path
path = f.getPath();
// prints
System.out.println(path+" is absolute? "+ bool);
// create new file
f = new File("test.txt");
// true if the file path is absolute, else false
bool = f.isAbsolute();
// get the path
path = f.getPath();
// prints
System.out.print(path+" is absolute? "+bool);
}catch(Exception e){
// if any error occurs
e.printStackTrace();
}
}
}
Let us compile and run the above program, this will produce the following result:
C:\test.txt is absolute? true test.txt is absolute? false