2017년 9월 11일 월요일

[JaVa] URL 읽어 들이기

        StringBuffer _sb = new StringBuffer();

        try {
            URL _url = new URL("http://dev.freecatz.pe.kr:8080/web/sample2");
            URLConnection _conn = _url.openConnection();
            InputStream _is = _conn.getInputStream();
            InputStreamReader _isr = new InputStreamReader(_is, "UTF-8");
            BufferedReader _br = new BufferedReader(_isr);
             
            String _temp;
            while((_temp = _br.readLine()) != null){
             _sb.append(_temp + "\r\n") ;
            }
            System.out.println(_sb.toString()) ;
             
        } catch (MalformedURLException mf) {
         mf.printStackTrace();
        } catch (IOException ioe) {
         ioe.printStackTrace();
        }