读书人

url.openStream()和url.openConnectio

发布时间: 2013-11-25 13:22:27 作者: rapoo

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()

读书人网 >J2SE开发

热点推荐