下面粘贴的代码来自HttpURLConnection上的java docs。

我收到以下错误:

readStream(in)

因为没有这种方法。

我看到同样的事情
URLConnection的类概述位于
URLConnection.getInputStream()
readStream在哪里?下面提供了代码段:
 URL url = new URL("http://www.android.com/");
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    try
    {
        InputStream in = new BufferedInputStream(urlConnection.getInputStream());
        readStream(in);  <-----NO SUCH METHOD
    }
    finally
    {
        urlConnection.disconnect();
    }

最佳答案

尝试使用以下代码:

InputStream in = address.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder result = new StringBuilder();
String line;
while((line = reader.readLine()) != null) {
    result.append(line);
}
System.out.println(result.toString());

关于java - 如何读取HTTP输入流,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9856195/

10-12 20:49