【问题标题】:Set timeout when loading xml from a URL?从 URL 加载 xml 时设置超时?
【发布时间】:2012-05-03 08:41:29
【问题描述】:

直接从 URL 加载 xml 时是否可以设置超时?

Builder parser = new Builder();
Document doc = parser.build("http://somehost");

这有时可能需要几分钟,如果能够直接在库中将其超时会非常方便。

【问题讨论】:

    标签: java xom


    【解决方案1】:

    您需要使用 build(InputStream inStream) api 而不是 build(String systemID)。

    URL url = new URL("http://somehost");
    con = url.openConnection();
    con.setConnectTimeout(connectTimeout);
    con.setReadTimeout(readTimeout);
    inStream = con.getInputStream();
    Builder parser = new Builder();
    Document doc = parser.build(inStream);
    

    【讨论】:

      猜你喜欢
      • 2012-05-11
      • 1970-01-01
      • 2011-04-11
      • 1970-01-01
      • 2012-03-27
      • 1970-01-01
      • 2012-07-21
      • 2019-05-15
      • 1970-01-01
      相关资源
      最近更新 更多