在被斥责建议 URL 类之后。我将采纳评论者的建议,建议使用 URI 类。我建议您仔细研究 URI 的构造函数,因为这个类一旦创建就是不可变的。
我认为这个构造函数允许您在 URI 中设置可能需要的所有内容。
URI(String scheme, String userInfo, String host, int port, String path, String query, String fragment)
Constructs a hierarchical URI from the given components.