本文介绍了如何读取HTTP输入流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面粘贴的代码来自Javadocs上的 HttpURLConnection
.
The code pasted below was taken from Javadocs on
HttpURLConnection
.
我收到以下错误:
readStream(in)
...因为没有这种方法.
...as there is no such method.
我在URLConnection的类概述中看到了相同的内容,
URLConnection.getInputStream
I see this same thing in the Class Overview for URLConnection at
URLConnection.getInputStream
readStream
在哪里?下面提供了代码段:
Where is
readStream
? The code snippet is provided below:
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());
这篇关于如何读取HTTP输入流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!