`

URL类openStream方法和openConnection方法的区别

URL 
阅读更多

        可以看Java帮助文档,就能清楚它们之间的区别:

        public URLConnection openConnection() throws IOException——返回一个URLConnection对象,它表示到URL所引用的远程对象的连接。每次调用此URL的协议处理程序的openConnection方法都打开一个新的连接。如果URL的协议(例如,HTTP或JAR)存在属于以下包或其子包之一的公共、专用URLConnection子类:java.lang、java.io、java.util、java.net,返回的连接将为该子类的类型。例如,对于HTTP,将返回HttpURLConnection,对于JAR,将返回JarURLConnection。(返回到该URL的URLConnection!)

        public final InputStream openStream() throws IOException——打开到此URL的连接并返回一个用于从该连接读入的InputStream。此方法是下面方法的缩写:openConnection().getInputStream()。(返回从URL连接读入的输入流!)

分享到:
评论

相关推荐

    详解PHP内置访问资源的超时时间 time_out file_get_contents read_file

    [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 500 Read timed outin D:\website\extra.php on line 65”我在程序的开始已经有set_time_limit(0);了啊,那上面的错误会是因...

    GetHttp:请求获取http 个人简单测试工具

    测试 url 网络资源请求获取 url.openStream() eg:网络图片 测试 urlConnetction 网络资源\数据 获取 urlConnection = url.openConnection(); 测试 HttpURLConnetction 网络资源\数据 获取 HttpURLConnection = url....

    C#全能速查宝典

    1.2 数学方法类——Math 25 1.2.1 Abs方法——返回指定数字的绝对值 25 1.2.2 Acos方法——返回余弦值为指定数字的角度 26 1.2.3 Asin方法——返回正弦值为指定数字的角度 26 1.2.4 Atan方法——返回正切值为指定...

    HttpClient以及获取页面内容应用

    BufferedReader reader = new BufferedReader(new InputStreamReader(pageUrl.openStream(), "utf-8")); // Read page into buffer. String line; while ((line = reader.readLine()) != null) { ...

    Android 上传文件工具类

    HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(TIME_OUT); conn.setConnectTimeout(TIME_OUT); conn.setDoInput(true); // 允许输入流 conn.setDoOutput...

    一个web爬虫的事例.txt

    new InputStreamReader(robotsFileUrl.openStream())); // 读robot文件,创建不允许访问的路径列表。 String line; while ((line = reader.readLine()) != null) { if (line.indexOf("Disallow:") == 0) {// ...

    c# http post get

    public Stream GetStream(string URL, string postData) { byte[] sendBytes = encoding.GetBytes(postData); postStream = new MemoryStream(); postStream.Write(sendBytes, 0, sendBytes.Length); ...

    微信企业号项目

    HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection(); conn.setRequestMethod("POST"); conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); //请求头 conn....

    esp8266 mp3

    //Open a connection to a webserver and request an URL. Yes, this possibly is one of the worst ways to do this, //but RAM is at a premium here, and this works for most of the cases. int ICACHE_FLASH_...

    js使用小技巧

    " 和 "?"也编码 表格行指示 //各种尺寸 s += " 网页可见区域宽:"+ document.body.clientWidth; s += " 网页可见区域高:"+ document.body.clientHeight; s += " 网页可见区域高:"+ document.body....

    netcat 瑞士军刀 linux windows netcat 瑞士军刀 linux windows

    本软件包含windows和linux两种版本 1、 了解NC的用法 命令:  nc –h 技巧:  win98用户可以在autoexec.bat加入path=nc的路径,win2000用户在环境变量中加入path中,linux含有这个命令(redhat) 1、基本使用  ...

    fso浏览54646465465464564

    '========================== 版权声明 ========================= '本程序只供在需要特别处理服务器文件时使用,严禁用于非法目的 '由于非正当使用本程序而造成的一切后果及责任自负 '版本: v0.12 ...

    php.ini-development

    url_rewriter.tags ; Default Value: "a=href,area=href,frame=src,form=,fieldset=" ; Development Value: "a=href,area=href,frame=src,input=src,form=fakeentry" ; Production Value: "a=href,area=href,frame=...

    asp连接数据库代码实例

    set conn=server.createobject(\"adodb.connection\") conn.open \"driver={microsoft access driver (*.mdb)};dbq=\"&server.mappath(db) if err then err.clear set conn = Nothing response.write \"数据库...

    Java邮件开发Fundamentals of the JavaMail API

    be an open relay, as authentication is supported, but it is your responsibility to ensure the SMTP server is configured properly. There is nothing in the JavaMail API for tasks like configuring a ...

    python3.6.5参考手册 chm

    Python参考手册,官方正式版参考手册,chm版。以下摘取部分内容:Navigation index modules | next | Python » 3.6.5 Documentation » Python Documentation contents What’s New in Python ...

    小偷,采集程序常用函数

    [removed] //连接数据库 function connOpen(DataBaseConnectStr){ var conn = Server.CreateObject(“ADODB.Connection”); conn.Open(DataBaseConnectStr); return conn; } //利用AdoDb.Stream对象来读取指定...

Global site tag (gtag.js) - Google Analytics