java URL URLConnection _JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > java URL URLConnection

java URL URLConnection

 2011/10/14 9:38:49  XIAOLINJAVA  http://xiaolinjava.iteye.com  我要评论(0)
  • 摘要:importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStream;importjava.io.InputStreamReader;importjava.net.URL;importjava.net.URLConnection;importjava.util.ArrayList;importjava.util.List;publicclassWebUrlRequestBuilder
  • 标签:Java URL
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

public class WebUrlRequestBuilder {


	public static URLConnection webUrlRequest(String requestUrl) throws IOException {
		return new URL(requestUrl).openConnection();
	}

	public static List<String> readLine(InputStream inputStream) throws IOException {
		List<String> list = new ArrayList<String>();
		BufferedReader bufferReader = null;
		try {
			bufferReader = new BufferedReader(new InputStreamReader(inputStream));
			
			String readline;
			while ((readline = bufferReader.readLine()) != null) {
				list.add(readline);
			}
		} finally {
			bufferReader.close();
		}
		return list;
		
	}

	public static void main(String[] args) throws IOException {
		URLConnection webUrlRequest = webUrlRequest("http://www.360buy.com");
		List<String> readline = readLine(webUrlRequest.getInputStream());
		
		System.out.println(readline);
	}
}

  • WebUrlRequestBuilder.rar (540 Bytes)
  • 下载次数: 0
上一篇: 人一辈子 下一篇: JSONObject
发表评论
用户名: 匿名