Last active
December 21, 2015 02:08
-
-
Save wdfx100/6232463 to your computer and use it in GitHub Desktop.
URL类
This file contains 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
URL url = new URL("http://www.baidu.com"); | |
URLConnection conn =url.openConnection(); | |
InputStream stream = conn.getInputStream(); | |
//字符流 | |
BufferedReader reader = new BufferedReader(new InputStreamReader(stream,"UTF-8")); | |
String str = null; | |
StringBuffer sb = new StringBuffer(); | |
while((str=reader.readLine())!=null){ | |
sb.append(str); | |
} | |
reader.close(); | |
System.out.println(sb.toString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment