Created
February 28, 2016 21:54
-
-
Save AnnaBoro/2fbeb9b3fdf11ce7c2c4 to your computer and use it in GitHub Desktop.
get content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lesson8.serialization; | |
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.net.URL; | |
import java.net.URLConnection; | |
public class Demo { | |
public static void main(String[] args) | |
{ | |
String output = getUrlContents("http://cloud-notes.blogspot.com/2011/02/java_1822.html"); | |
System.out.println(output); | |
} | |
public static String getUrlContents(String theUrl) { | |
StringBuilder content = new StringBuilder(); | |
try { | |
URL url = new URL(theUrl); | |
URLConnection urlConnection = url.openConnection(); | |
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); | |
String line; | |
while ((line = bufferedReader.readLine()) != null) { | |
content.append(line + "\n"); | |
} | |
bufferedReader.close(); | |
} | |
catch(Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
return content.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment