从网络数据库解析xml文件时出现问题

发布于 2024-10-27 06:28:07 字数 246 浏览 6 评论 0原文

在我的应用程序中,我从网络数据库获取一个 xml 文件,我的整体编码中只有一个错误,

它在我提到输入的行中显示错误,

我将输入提到为

url = new InputStream (http://siva.com);

它用红线标记了InputStream一词,并显示错误为无法实例化类型InputStream

如何给出URL的输入,请帮助我....

in my app i am getting a xml file from a network database, i have only one error in my overall coding,

it shows error in the line where i have mention the input,

i am mentioning the input as

url = new InputStream(http://siva.com);

it marks the word InputStream with red line and shows the error as Cannot instantiate the type InputStream

How to give the input of an URL, pls help me....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

若相惜即相离 2024-11-03 06:28:07

是的,你不能实例化InputStream,看看这个: http:// /download.oracle.com/javase/tutorial/networking/urls/readingURL.html

导入java.net.*;
导入java.io.*;
公共类 URLReader {
    公共静态无效主(字符串[] args)抛出异常{
    URL yahoo = 新 URL("http://www.yahoo.com/");
    BufferedReader in = new BufferedReader(
            新的输入流读取器(
            yahoo.openStream()));
    字符串输入行;
    while ((inputLine = in.readLine()) != null)
        System.out.println(inputLine);
    附寄();
    }
}

yeah, you can not instantiate InputStream, have a look at this: http://download.oracle.com/javase/tutorial/networking/urls/readingURL.html

import java.net.*;
import java.io.*;
public class URLReader {
    public static void main(String[] args) throws Exception {
    URL yahoo = new URL("http://www.yahoo.com/");
    BufferedReader in = new BufferedReader(
            new InputStreamReader(
            yahoo.openStream()));
    String inputLine;
    while ((inputLine = in.readLine()) != null)
        System.out.println(inputLine);
    in.close();
    }
}
花期渐远 2024-11-03 06:28:07
URL url = new URL("http://siva.com");
URLConnection uc = url.openConnection();

InputStreamReader input = new InputStreamReader(uc.getInputStream());
URL url = new URL("http://siva.com");
URLConnection uc = url.openConnection();

InputStreamReader input = new InputStreamReader(uc.getInputStream());
手心的温暖 2024-11-03 06:28:07

再来一次:-)

            // Send data
            URL url = new URL("##YOURURL##");
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write(data);
            wr.flush();

            // Get the response
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            line = rd.readLine();
            if(line != null) {
                System.out.println(line);
            }

            wr.close();
            rd.close();

Another go at it :-)

            // Send data
            URL url = new URL("##YOURURL##");
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write(data);
            wr.flush();

            // Get the response
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            line = rd.readLine();
            if(line != null) {
                System.out.println(line);
            }

            wr.close();
            rd.close();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文