함수 의 값 읽 기 연습

2285 단어 함수.
String getInput(){  

        String str="";

        try  

        {  

        URL url = new URL("http://www.baidu.com/");  

        HttpURLConnection conn = (HttpURLConnection) url.openConnection();  

        conn.setDoInput(true);  

        conn.setConnectTimeout(10000);  

        conn.setRequestMethod("GET");  

        conn.setRequestProperty("accept", "*/*");  

        String location = conn.getRequestProperty("location");  

        int resCode = conn.getResponseCode();  

        conn.connect();  

        InputStream stream = conn.getInputStream();  

        byte[] data=new byte[102400];  

        int length=stream.read(data);  

         str=new String(data,0,length);  

        conn.disconnect();  

        System.out.println(str);  

        stream.close();  

        

        }  

        catch(Exception ee)  

        {  

        System.out.print("ee:"+ee.getMessage());   

        } 

        return str; //  str

        } 

 
  
호출 방법          String a= getInput();

좋은 웹페이지 즐겨찾기