[英]How to check whether the path is relative or absolute in java?
I am developing a tool, which takes a path of an xml
file.我正在开发一个工具,它需要一个
xml
文件的路径。 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.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()) {
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.