How to construct a relative path in Java from two absolute paths (or URLs)?

前端 未结 22 2734
小蘑菇
小蘑菇 2020-11-22 10:30

Given two absolute paths, e.g.

/var/data/stuff/xyz.dat
/var/data

How can one create a relative path that uses the second path as its base?

22条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 10:55

    The bug referred to in another answer is addressed by URIUtils in Apache HttpComponents

    public static URI resolve(URI baseURI,
                              String reference)
    

    Resolves a URI reference against a base URI. Work-around for bug in java.net.URI ()

提交回复
热议问题