Java Path接口已添加到Java 7中的Java NIO。Java.nio.file.Path的isAbsolute()方法用于检查此路径是否为绝对路径。当且仅当此路径是绝对路径时,此方法才返回true。绝对路径是无需与其他路径信息结合即可找到文件的路径。
用法:
boolean isAbsolute()
参数:此方法不接受任何内容。
返回值:仅当此路径是绝对路径时,此方法才返回true。
以下示例程序旨在说明isAbsolute()方法:
示例1:
// Java program to demonstrate
// java.nio.file.Path.isAbsolute() method
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
public class GFG {
public static void main(String[] args)
throws IOException
{
// create an object of Path
Path path
= Paths.get("D:\\eclipse\\configuration"
+ "\\org.eclipse.update");
// call isAbsolute() to get check
// path is absolute or not
boolean isAbsolute = path.isAbsolute();
// print isAbsolute
System.out.println("Path is Absolute: "
+ isAbsolute);
}
}
输出:
示例2:
// Java program to demonstrate
// java.nio.file.Path.isAbsolute() method
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
public class GFG {
public static void main(String[] args)
throws IOException
{
// create object of Path
Path path = Paths.get("temp\\Spring");
// call isAbsolute() to get check
// path is absolute or not
boolean isAbsolute = path.isAbsolute();
// print isAbsolute
System.out.println("Path is Absolute: "
+ isAbsolute);
}
}
输出: