Authority =
Default port =
File = /articles/l
Host =
Path = /articles/l
Port =
Protocol = http
Query = null
Ref = null
User Info = null
<html>
<head>
<title>
Java Jeff
</title>
<meta http
charset=ISO
<meta name=author content=
<meta name=keywords content=
<script language=JavaScript>
if (navigator
document
</script>
</head>
<body bgcolor=#
<center>
<table border=
<tr>
<td>
<table cellpadding=
<tr>
<td>
<a href=informit/l>
<img alt=InformIT border=
</td>
</tr>
</table>
</td>
<td align=middle>
<img src=title
<a href=
<img alt=
</a><br>
<img src=
<a href=
<img alt=
rc=jupiter
</td>
<td>
<table cellpadding=
<tr>
<td>
<a href=javaworld/l>
<img alt=JavaWorld border=
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
<br>
<font color=#ffffff>
<center>
Best viewed at a resolution of
<img src=
<i>
Copyright ?
reserved
</i>
<p>
<a href=
<img alt=Back border=
</center>
</font>
</body>
</html>
在上面的信息中
URL的openStream()方法通常返回抽象的InputStream類的一個具體的子類所建立的對象的引用
下面的代碼片斷演示了把一個InputStream對象包裝進java
InputStream is = url
BufferedReader br = new BufferedReader (new InputStreamReader (is));
String line;
while ((line = br
System
is
有時候按字節的次序讀取數據並不方便
當調用getContent()方法時
對於JPEG資源
URL url = new URL (args [
Object o = url
if (o instanceof ImageProducer)
{
ImageProducer ip = (ImageProducer) o;
//
}
技巧
調用URL的equals(Object o)和sameFile(Object o)方法來決定兩個URL是否相同
查看一下getContent()方法的源代碼
這個方法返回抽象的
列表
列表
// URLDemo
import java
import
import java
class URLDemo
{
ublic static void main (String [] args) throws IOException
{
if (args
{
System
return;
}
URL url = new URL (args [
// 返回代表某個資源的連接的新的特定協議對象的引用
URLConnection uc = url
// 進行連接
nnect ();
// 打印多種頭部字段的內容
Map m = uc
Iterator i = m
while (i
System
// 如果資源允許輸入和輸出操作就找出來
System
System
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26109.html