Java 无法理解URLConnection的getInputStream()

Java 无法理解URLConnection的getInputStream(),java,android,url,networking,Java,Android,Url,Networking,下面是在URLConnection中定义的getInputStream()的代码 public InputStream getInputStream() throws IOException { throw new UnknownServiceException("Does not support writing to the input stream"); } 我使用它在代码中获取inputstream对象 private String makeHttpRequest

下面是在URLConnection中定义的getInputStream()的代码

public InputStream getInputStream() throws IOException {
        throw new UnknownServiceException("Does not support writing to the input stream");
    }
我使用它在代码中获取inputstream对象

private String makeHttpRequest(URL url) throws IOException {
            String jsonResponse = "";
            HttpURLConnection urlConnection = null;
            InputStream inputStream = null;
            try {
                urlConnection = (HttpURLConnection) url.openConnection();
                urlConnection.setRequestMethod("GET");
                urlConnection.setReadTimeout(10000 /* milliseconds */);
                urlConnection.setConnectTimeout(15000 /* milliseconds */);
                urlConnection.connect();
                inputStream = urlConnection.getInputStream();
                jsonResponse = readFromStream(inputStream);
            } catch (IOException e) {
                // TODO: Handle the exception
            } finally {
                if (urlConnection != null) {
                    urlConnection.disconnect();
                }
                if (inputStream != null) {
                    // function must handle java.io.IOException here
                    inputStream.close();
                }
            }
            return jsonResponse;
        }
inputStream=urlConnection.getInputStream()


这个语句是如何工作的,因为在其定义中它抛出了一个未知的ServiceException()??不能写入输入流。不可能的。您只能从输入流中读取。错误消息。@RobyJacob没有,但连接是从
URL
中检索的,该URL委托给
URLStreamHandler
,在这种情况下,我怀疑
sun.net.www.protocol.http.Handler
,这很可能会创建另一个子类。如果您确实需要了解实现的详细信息,请逐步使用调试器。