码迷,mamicode.com
首页 > 编程语言 > 详细

java之URL(URL,URLConnection)实例

时间:2014-10-28 12:21:21      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:java   网络编程   url   urlconnection   通信   

import org.junit.Test;

public class TestURL {

	@Test
	public void readUrl() throws Exception{
		
		URL url = new URL("http://localhost:8088/gress/data/reportData_201401.xml?a=b");
		
		System.out.println(url.getProtocol());
		System.out.println(url.getHost());
		System.out.println(url.getPort());
		System.out.println(url.getPath());
		System.out.println(url.getFile());
		System.out.println(url.getRef());
		System.out.println(url.getQuery());
		
		URLConnection  urlConn = url.openConnection();
		BufferedReader buffReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
		
		String str = null;
		while((str = buffReader.readLine()) != null ){
			System.out.println(str);
		}
		
		buffReader.close();
		
		
	}

}

java之URL(URL,URLConnection)实例

标签:java   网络编程   url   urlconnection   通信   

原文地址:http://blog.csdn.net/sd_tz_wzg/article/details/40536747

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!