java之URL(URL,URLConnection)实例
Posted ljbguanli
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java之URL(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)实例的主要内容,如果未能解决你的问题,请参考以下文章