⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 right8_2_4.htm

📁 清华大学JAVA教程
💻 HTM
字号:
<html><head><title>JAVA编程语言</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><link rel="stylesheet" href="../../../css/text.css" type="text/css"></head><body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" ><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">  <tr>     <td valign="top">       <table width="97%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" align="center">        <tr>          <td height="244" valign="top">             <p class="pt9-black">   一个URL对象生成后,其属性是不能被改变的,但是我们可以通过类URL所提供的方法来获取这些属性:<br>                 public String getProtocol() 获取该URL的协议名。<br>                 public String getHost() 获取该URL的主机名。<br>                 public int getPort() 获取该URL的端口号,如果没有设置端口,返回-1。<br>                 public String getFile() 获取该URL的文件名。<br>                 public String getRef() 获取该URL在文件中的相对位置。<br>                 public String getQuery() 获取该URL的查询信息。<br>                 public String getPath() 获取该URL的路径<br>                 public String getAuthority() 获取该URL的权限信息<br>                 public String getUserInfo() 获得使用者的信息<br>                 public String getRef() 获得该URL的锚</p>            <p class="pt9-black"><br>                下面的例子中,我们生成一个URL对象,并获取它的各个属性。</p>            <p class="pt9-black">  import java.net.*;<br>                import java.io.*;</p>            <p class="pt9-black">  public class ParseURL{<br>                public static void main (String [] args) throws Exception{</p>            <p class="pt9-black">  URL Aurl=new URL(&quot;http://java.sun.com:80/docs/books/&quot;);<br>                URL tuto=new URL(Aurl,&quot;tutorial.intro.html#DOWNLOADING&quot;);	              <br>                System.out.println(&quot;protocol=&quot;+ tuto.getProtocol());<br>                System.out.println(&quot;host =&quot;+ tuto.getHost());<br>                System.out.println(&quot;filename=&quot;+ tuto.getFile());<br>                System.out.println(&quot;port=&quot;+ tuto.getPort());<br>                System.out.println(&quot;ref=&quot;+tuto.getRef());<br>                System.out.println(&quot;query=&quot;+tuto.getQuery());<br>                System.out.println(&quot;path=&quot;+tuto.getPath());<br>                System.out.println(&quot;UserInfo=&quot;+tuto.getUserInfo());<br>                System.out.println(&quot;Authority=&quot;+tuto.getAuthority());<br>                }<br>                }<br>              <br>                执行结果为:<br>                 protocol=http host =java.sun.com filename=/docs/books/tutorial.intro.html               <br>                 port=80 <br>                 ref=DOWNLOADING <br>                 query=null <br>                 path=/docs/books/tutorial.intro.html <br>                 UserInfo=null <br>                 Authority=java.sun.com:80<br>            </p>            <p class="pt9-black"> <span class="pt9-black"><br>              </span></p>            <p class="pt9-black"><span class="pt9-black"><br>              </span> </p>          </td>        </tr>      </table>    </td>  </tr></table></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -