开发者

How to check whether the path is relative or absolute in java?

I am developing a tool, which takes a path of an xml f开发者_开发百科ile. Now that path can be either relative or absolute. Inside the code, when I have only a string, is there a way to identify that the path is absolute or relative?


How about File.isAbsolute():

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


There is another very similar way using Paths operations:

Path p = Paths.get(pathName); 
if (p.isAbsolute()) {
    ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜