Skip to content

Instantly share code, notes, and snippets.

@wdfx100
Last active December 21, 2015 02:08
Show Gist options
  • Save wdfx100/6232463 to your computer and use it in GitHub Desktop.
Save wdfx100/6232463 to your computer and use it in GitHub Desktop.
URL类
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