集册 Java实例教程 获取URL属性

获取URL属性

欢马劈雪     最近更新时间:2020-01-02 10:19:05

449
获取URL属性
/*时 代      J a v a   公   众 号 - nowjava.com 提 供*/


import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.UnsupportedEncodingException;

import java.net.MalformedURLException;

import java.net.URL;

import java.net.URLEncoder;


public class UrlClass {


    public static void main(String[] args) throws IOException {

        new UrlClass().example4();

    }
/**时 代 J a v a 公 众 号**/

    private void example4() throws UnsupportedEncodingException {

        System.out.println(URLEncoder.encode("String with spaces", "UTF-8"));

        System.out.println(URLEncoder.encode("English", "UTF-8"));

        System.out.println(URLEncoder.encode("Special chars: &%*", "UTF-8"));

    }


    private void example3() throws MalformedURLException {

        URL uri = new URL("http://docs.oracle.com/javase/tutorial/index.html?name=networking#DOWNLOADING");

        System.out.println("getProtocol:" + uri.getProtocol());

        System.out.println("getAuthority:" + uri.getAuthority());

        System.out.println("getHost:" + uri.getHost());

        System.out.println("getPort:" + uri.getPort());

        System.out.println("getPath:" + uri.getPath());

        System.out.println("getQuery:" + uri.getQuery());

        System.out.println("getFile:" + uri.getFile());

        System.out.println("getRef:" + uri.getRef());


    }


    private void examle1() throws IOException {


        URL uri = new URL(

                "https://www.google.co.kr/images/branding/product/ico/googleg_lodp.ico");

        Object object = uri.getContent();


    }


    private void example2() throws 
展开阅读全文