잡동사니에도 사랑을

[21.08.31] URLMain 본문

JAVA_SE/12_network

[21.08.31] URLMain

luvforjunk 2021. 9. 1. 00:21
728x90
반응형

package network;

 

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.net.URL;

 

public class URLMain {

 

         public static void main(String[] args) throws IOException {

                  URL url = new URL("https://www.naver.com/index.html");

                  System.out.println("프로토콜 = " + url.getProtocol()); // https

                  System.out.println("호스트 = " + url.getHost()); // www.naver.com

                  System.out.println("포트 = " + url.getPort()); // 포트 번호가 없는뎅? ...-1

                  System.out.println("기본포트 = " + url.getDefaultPort()); // 443

                  System.out.println("파일 = " + url.getFile()); // /index.html

 

                  BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));

                  String line = null;

 

                  while ((line = br.readLine()) != null) {

                           System.out.println(line);

                  }

                  br.close();

         }

}

 

728x90
반응형

'JAVA_SE > 12_network' 카테고리의 다른 글

[21.08.31] Protocol Server와 Client 연동  (0) 2021.09.01
[21.08.31] InetAddress  (0) 2021.09.01