如何读取http输入流(How to read an http input stream)
下面粘贴的代码取自HttpURLConnection上的java文档。
我收到以下错误:
readStream(in)因为没有这样的方法。
我在URLConnection.getInputStream() URLConnection类概览中看到同样的事情,
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(); }The code pasted below was taken from java docs on HttpURLConnection.
I get the following error:
readStream(in)as there is no such method.
I see this same thing in the Class Overview for URLConnection at URLConnection.getInputStream()
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());Try with this code:
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());更多推荐
发布评论