import java.net.MalformedURLException;
import java.net.URL;
public class Main {
public static void main(String[] args) {
String urlString = "https://www.example.com/path/to/resource";
try {
URL url = new URL(urlString);
// ドメインを取得する
String domain = url.getHost();
System.out.println("ドメイン: " + domain);
// ドメイン以降の部分を取得する
String path = url.getPath();
System.out.println("ドメイン以降の部分: " + path);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
ドメイン: www.example.com
ドメイン以降の部分: /path/to/resource