如何检查文件路径是否相对于另一个文件路径?

时间:2014-03-10 15:46:30

标签: java file url path

如果我有路径:

String path = "/some/path"

如何检查其他路径是否与其相关(鉴于我要将'anotherPath'连接到'path')?

例如:

String anotherPath = ""; // relative = true 
// will result in a full path of "/some/path"

String anotherPath = "/some/more"; // relative = true
// will result in a full path of "/some/path/some/more"

String anotherPath = "some/more"; // relative = true
// will result in a full path of "/some/path/some/more"

String anotherPath = "../../trying/go/up"; // relative = false
// would result in an INVALID full path of "/trying/go/up"

String anotherPath = "../more"; // relative = true
// will result in a full path of "/some/more"

此外,是否可以仅使用字符串而不是文件或URL对象进行这些检查? (因为我无法写入文件系统)

0 个答案:

没有答案