如何将一个String对象转换成InputStream对象?
ByteArrayInputStream inputStream = new ByteArrayInputStream(str.getBytes());
String baseURL = "http://sixweather.3gpk.net/SixWeather.aspx?city=%s"; String cityName = "武汉"; String resultURL = String.format(baseURL, cityName);
如何在Java中访问网络地址,获取返回结果?
// **************访问网络,获取天气预报数据,将结果数据存储到result中******************* //初始化httpGet,将参数url传给它 HttpGet httpGet = new HttpGet(url); String result = ""; //初始化httpClient HttpClient httpClient = new DefaultHttpClient(); //调用httpClient的execute方法,返回一个HttpResponse的实例 HttpResponse httpResponse = httpClient.execute(httpGet); if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { //将httpResponse中的天气数据转换成字符串形式 result = EntityUtils.toString(httpResponse.getEntity()); } // ****************************************************************************************
如何在Java中对字符串String进行编码、解码操作?
String cityName = "武汉"; try { //对cityName进行utf-8编码操作 cityName = URLEncoder.encode(cityName, "utf-8"); //对cityName进行utf-8解码操作 cityName = URLDecoder.decode(cityName, "utf-8"); } catch (Exception e) { e.printStackTrace(); }
原文地址:http://blog.csdn.net/bear_huangzhen/article/details/25588839