2.1. 페ì�´ì§€ ê¸�어오기 ¶
어디서 �어온 코드.
import java.net.URL;
import java.net.URLConnection;
import java.net.MalformedURLException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
public class URLConn{
public static void main(String args[]){
URL url;//URL 주소 �체
URLConnection connection;//URLì ‘ì†�ì�„ 가지는 ê°�ì²´
InputStream is;//URLì ‘ì†�ì—�서 ë‚´ìš©ì�„ ì�½ê¸°ìœ„한 Stream
InputStreamReader isr;
BufferedReader br;
try{
//URLê°�체를 ìƒ�ì„±í•˜ê³ í•´ë‹¹ URL로 ì ‘ì†�한다..
url = new URL("http://www.hufslife.com/");
connection = url.openConnection();
//내용� �어오기위한 InputStream�체를 �성한다..
is = connection.getInputStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
//ë‚´ìš©ì�„ ì�½ì–´ì„œ 화면ì—� ì¶œë ¥í•œë‹¤..
String buf = null;
while(true){
buf = br.readLine();
if(buf == null) break;
System.out.println(buf);
}
}catch(MalformedURLException mue){
System.err.println("잘못� URL입니다. 사용법 : java URLConn http://hostname/path]");
System.exit(1);
}catch(IOException ioe){
System.err.println("IOException " + ioe);
ioe.printStackTrace();
System.exit(1);
}
}
};










