谢谢大家帮忙。
现在有这样一个问题:
一个网站从google获取天气信息,但打开网页时很慢,大概的6-7秒钟才能打开,经测试是由于代码中url.openStream()执行的慢导致的!
现在想知道以什么样的方式能达到获取到天气信息又能使网页很快就显示出来!!!谢谢!
代码如下!
  String ur = "http://www.google.com/ig/api?hl=zh_cn&weather=";
/*  36 */       URL url = new URL(ur + city);
/*  37 */       InputStream in = url.openStream();
//InputStream in = null;
/*  39 */       ByteArrayOutputStream bos = new ByteArrayOutputStream();
/*  40 */       int i = -1;
/*  41 */       while ((i = in.read()) != -1) {
/*  42 */         bos.write(i);
/*     */       }
/*  44 */       InputStream inp = new ByteArrayInputStream(bos.toString().getBytes(
/*  45 */         "utf-8"));
/*     */ 
/*  47 */       Document doc = DocumentBuilderFactory.newInstance()
/*  48 */         .newDocumentBuilder().parse(inp);
/*  49 */       NodeList n1 = getNode(doc, "forecast_information", 0);
/*     */ 
/*  51 */       weatherInfo.setWeatherDate(getAttributeValue(n1, 4, 0));