Home > Java > javaTutorial > body text

Java Example - Parsing URL

黄舟
Release: 2017-01-21 10:48:49
Original
1594 people have browsed it

The following examples demonstrate how to use the url.getProtocol(), url.getFile() and other methods of the net.URL class to parse URL addresses:

/*
 author by w3cschool.cc
 Main.java
 */import java.net.URL;public class Main {
   public static void main(String[] args) 
   throws Exception {
      URL url = new URL("http://www.w3cschool.cc/html/html-tutorial.html");
      System.out.println("URL 是 " + url.toString());
      System.out.println("协议是 " 
      + url.getProtocol());
      System.out.println("文件名是 " + url.getFile());
      System.out.println("主机是 " + url.getHost());
      System.out.println("路径是 " + url.getPath());
      System.out.println("端口号是 " + url.getPort());
      System.out.println("默认端口号是 " 
      + url.getDefaultPort());
   }}
Copy after login

The above code runs the output results For:

URL 是  
协议是 http文件名是 /html/html-tutorial.html
主机是  
路径是 /html/html-tutorial.html
端口号是 -1默认端口号是 80
Copy after login

The above is the Java example - parsing the content of the URL. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!