java学习(164):url

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.MalformedInputException;

//url
public class test111 {
    public static void main(String[] args){
        try {
            URL baiduUrl = new URL( "http://www.baidu.com" );
            URL url2=new URL( "https","localhost",9090,"java.jpg" );
            URL url3=new URL(baiduUrl,"index.html");
            try {
                System.out.println("上下文"+baiduUrl.getContent().toString());
                System.out.println( "请求的具体资源"+ url3.getFile()  );
                System.out.println( "服务器名称"+url3.getHost() );
                System.out.println( "协议"+url3.getProtocol() );
                System.out.println( "路径"+url3.getPath() );
            }catch (IOException e){
                e.printStackTrace();
            }
        }catch (MalformedURLException e){
            e.printStackTrace();
        }
    }
}

运行结果

java学习(164):url

 

上一篇:JAVA程序设计:最大间距(LeetCode:164)


下一篇:Revit中如何将视图过滤器传递到其它项目