如何读取http输入流(How to read an http input stream)

编程入门 行业动态 更新时间:2024-10-11 15:22:45
如何读取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());

更多推荐

本文发布于:2023-07-06 07:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047447.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:read   http   stream   input

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!