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