无论程序当前运行的平台如何,Java中是否有任何方法可以确定给定路径是否是绝对路径。所以,我想要的可能是像下面的例子:在Linux上:newFile("/home/").isAbsolute()//Shouldreturntrue.newFile("C:/MyDocuments").isAbsolute()//Should*also*returntrue.在Windows上:newFile("C:/Documents").isAbsolute()//Shouldreturntrue.newFile("/home/").isAbsolute()//Should*also*returntr
我正在开发一个工具,它采用xml文件的路径。现在该路径可以是相对的或绝对的。在代码内部,当我只有一个字符串时,有没有办法识别路径是绝对的还是相对的? 最佳答案 File.isAbsolute()怎么样?:Filefile=newFile(path);if(file.isAbsolute()){...} 关于java-java中如何判断路径是相对的还是绝对的?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.c
我正在开发一个工具,它采用xml文件的路径。现在该路径可以是相对的或绝对的。在代码内部,当我只有一个字符串时,有没有办法识别路径是绝对的还是相对的? 最佳答案 File.isAbsolute()怎么样?:Filefile=newFile(path);if(file.isAbsolute()){...} 关于java-java中如何判断路径是相对的还是绝对的?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.c
.isAbsolute()的javadoc说:Tellswhetherornotthispathisabsolute.Anabsolutepathiscompleteinthatitdoesn'tneedtobecombinedwithotherpathinformationinordertolocateafile.Returns:trueif,andonlyif,thispathisabsolute.getRoot()的javadoc说:ReturnstherootcomponentofthispathasaPathobject,ornullifthispathdoesnothave