×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Samuel Sauvageau
Added: May 2, 2015 11:41 PM
Views: 4
Tags: no tags
Extracts source code from a given URL
  1.  private static String getUrlSource(String url) throws IOException {
  2.             URL yahoo = new URL(url);
  3.             HttpURLConnection yc = (HttpURLConnection) yahoo.openConnection();
  4.             StringBuilder sb;
  5.         try (BufferedReader in = new BufferedReader(new InputStreamReader(
  6.                 yc.getInputStream(), "UTF-8"))) {
  7.             String inputLine;
  8.             sb = new StringBuilder();
  9.             while ((inputLine = in.readLine()) != null)
  10.                 sb.append(inputLine);
  11.         }
  12.  
  13.             return sb.toString();
  14.         }