Java Socket Programming 大綱 - 網路資料庫實驗室
Java Socket Programming 大綱 - 網路資料庫實驗室
Java Socket Programming 大綱 - 網路資料庫實驗室
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
解析URL<br />
getProtocol<br />
Returns the protocol identifier component of the URL.<br />
getHost<br />
Returns the host name component of the URL.<br />
getPort<br />
Returns the port number component of the URL. The<br />
getPort method returns an integer that is the port<br />
number. If the port is not set, getPort returns -1.<br />
getFile<br />
Returns the filename component of the URL.<br />
getRef<br />
Returns the reference component of the URL.<br />
Example<br />
100. import java.net.*;<br />
101. import java.io.*;<br />
102. public class ParseURL {<br />
<strong>Java</strong> <strong>Socket</strong> <strong>Programming</strong> 23<br />
103. public static void main(String[] args) throws Exception {<br />
104. URL aURL = new URL("http://java.sun.com:80/docs/books/"<br />
105. + "tutorial/index.html#DOWNLOADING");<br />
106. System.out.println("protocol = " + aURL.getProtocol());<br />
107. System.out.println("host = " + aURL.getHost());<br />
108. System.out.println("filename = " + aURL.getFile());<br />
109. System.out.println("port = " + aURL.getPort());<br />
110. System.out.println("ref = " + aURL.getRef());<br />
111. }<br />
112. }<br />
<strong>Java</strong> <strong>Socket</strong> <strong>Programming</strong> 24<br />
12