如何在java中检查路径是相对路径还是绝对路径

如何在java中检查路径是相对路径还是绝对路径

问题描述:

我正在开发一个工具,它采用xml文件的路径,现在该路径可以是相对路径也可以是绝对路径。现在,在代码中,当我只有一个字符串时,有没有办法识别,路径是绝对的还是相对的。

I am developing a tool, which takes a path of an xml file, Now that path can be either relative or absolute. Now, Inside the code, when i have only a string, is there a way to identify, that the path is absolute or relative.

目前我正在使用一个标志来确定路径是相对的还是绝对的,但我需要摆脱它。

Currently i am using a flag to identify whether the path is relative or absolute, but i need to get rid of that.

问候。

如何 File.isAbsolute()

File file = new File(path);
if (file.isAbsolute()) {
    ...
}