假设一个 http 方案(即 新 URL(“http://www.google.com/”)
),IOException
不会被抛出到 myHttpURLConnection.connect()
而不是 myHttpURLConnection = myURL.openConection()
。
我的意思是 instanceURL.openConection()
似乎没有立即打开连接,如果是这样怎么会有 IOException
。
提前致谢。
最佳答案
当您调用 openConnection
时,将为指定的 URL 准备一个连接。如果 openConnection
由于给定的 URL 无效而无法准备连接,则会抛出 IOException
。
请参阅URL API了解更多信息。
关于java - 为什么 URL.openConection() 会抛出 IOException。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12666318/