Example: java_net_02.java
// URL を各要素に分解
import java.net.*;
public class java_net_02 {
public static void main(String[] args) {
try {
URL url = new URL(args[0]);
System.out.println("Schema : " + url.getProtocol());
System.out.println("Host : " + url.getHost());
System.out.println("Port : " + url.getPort());
System.out.println("Path : " + url.getFile());
System.out.println("Reference: " + url.getRef());
}
catch (Exception e) {
System.err.println(e);
return;
}
}
}
実行結果
> javac java_net_02.java > java java_net_02 http://localhost:80/new.html#hoge Schema : http Host : localhost Port : 80 Path : /new.html Reference: hoge
0 件のコメント:
コメントを投稿