android 获取天气信息,解决了乱码的问题
private static String getWeatherInfo3() { try { URL url = new URL("http://www.weather.com.cn/data/cityinfo/101060101.html"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); StringBuffer sb = new StringBuffer(); InputStreamReader input = new InputStreamReader(conn.getInputStream(),"utf-8"); Scanner inputStream = new Scanner(input); while (inputStream.hasNext()){ sb.append(inputStream.nextLine()); } System.out.println("weather3:"+sb.toString()); return sb.toString(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }