18
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

java.net.URLのgetメソッドで取得できるURLの部分

Last updated at Posted at 2014-12-24
メソッド 説明 戻り値 存在しない場合の戻り値
getQuery URL のクエリー部分 String null query=a&b=c
getPath URL のパス部分 String 空のString /path/to/page
getUserInfo URL のユーザー情報部分 String null user:password
getAuthority URL の機関部分 String user:password@host:80
getPort URL のポート番号 Int -1 80
getDefaultPort URL に関連するプロトコルのデフォルトのポート番号 Int -1 443
getProtocol URL のプロトコル名 String https
getHost URL のホスト名 String host
getFile URL のファイル名 String 空のString /path/to/page?query=a&b=c
getRef URL のアンカー String null hash
  • 例はnew java.net.URL("https://user:password@host:80/path/to/page?query=a&b=c#hash")で生成したインスタンスに対してメソッドを実行した場合。
  • Scalaから使うと、存在しない場合の戻り値がnullだったり-1だったりして辛いので、ラッパーを作るといいかもしれない…。
18
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?