首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

url.openStream()和url.openConnection().getInputStream()两者区别,该如何处理

2013-11-25 
url.openStream()和url.openConnection().getInputStream()两者区别url.openStream()和url.openConnection

url.openStream()和url.openConnection().getInputStream()两者区别
url.openStream()和url.openConnection().getInputStream()两者区别
[解决办法]
效果一样的。
可以看看API:
======================
 openStream

public final InputStream openStream()
                             throws IOException

    Opens a connection to this URL and returns an InputStream for reading from that connection. This method is a shorthand for:

             openConnection().getInputStream()
         

    Returns:
        an input stream for reading from the URL connection. 
    Throws:
        IOException - if an I/O exception occurs.
    See Also:
        openConnection(), URLConnection.getInputStream()



======================
 getInputStream

public InputStream getInputStream()
                           throws IOException

    Returns an input stream that reads from this open connection. A SocketTimeoutException can be thrown when reading from the returned input stream if the read timeout expires before data is available for read.

    Returns:
        an input stream that reads from this open connection. 
    Throws:
        IOException - if an I/O error occurs while creating the input stream. 
        UnknownServiceException - if the protocol does not support input.
    See Also:
        setReadTimeout(int), getReadTimeout()

热点排行